如何使用父级导航控制器以模态方式显示视图控制器?

发布于 2024-09-24 13:16:33 字数 1132 浏览 4 评论 0原文

我正在导航堆栈中间实现一个 UITabBar,而没有 UITabBarController。 UITabBar 位于 DetailViewController 中,它将屏幕的一部分委托给与所选选项卡元素关联的视图控制器。在通过选项卡栏选择显示的视图控制器之一内,有一个 UIButton 需要以模态方式显示视图。我尝试了 [selfpresentModalViewController:modalNavControlleranimated:YES];,但新的导航栏隐藏在父控制器 DetailViewController 的导航栏下方。所以我认为我需要做的是使用父级的导航控制器以模态方式呈现视图,以便新的导航栏位于 DetailViewController 导航栏的顶部。

我知道这是可能的,因为我在 DetailViewController 中有一个广告,点击添加可以给我带来所需的结果,但我无法合并该代码。我也可以从 DetailViewController 而不是子视图显示 UIButton,但我需要使用这种模式几次,所以我宁愿不必使用这样的非正统黑客。

谢谢!

编辑

我已经尝试将新视图添加到导航控制器,然后像这样呈现导航控制器:

WriteReviewController *newReview = [[WriteReviewController alloc] initWithNibName:@"WriteReviewController" bundle:nil];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:newReview];
// This is intended to be presented in another view controller class
modalNavController.navigationBar.barStyle = UIBarStyleDefault;  
[self.parentViewController presentModalViewController:modalNavController animated:YES]; 
[modalNavController release];

I'm implementing a UITabBar in the middle of my navigation stack without UITabBarController. The UITabBar is in the DetailViewController which delegate a portion of the screen to the view controller associated with the selected tab element. Inside one of view controller's thats displayed via tab bar selection, there's a UIButton which needs to display a view modally. I tried [self presentModalViewController:modalNavController animated:YES];, but the new navigation bar was hidden underneath the nav bar of the parent controller, DetailViewController. So what I think I need to do is use the parent's navigation controller to present the view modally so that the new nav bar is ON TOP of the DetailViewController nav bar.

I know its possible because I have an ad in the DetailViewController, and tapping the add gives me the desired result, but I haven't been able to incorporate that code. I could also probably display the UIButton from the DetailViewController rather than the subView, but I need to use this pattern a few times, so I'd rather not have to work with an unorthodox hack like that.

THANKS!

EDIT

I have already tried adding the new view to a navigation controller and then presenting the navigation controller like so:

WriteReviewController *newReview = [[WriteReviewController alloc] initWithNibName:@"WriteReviewController" bundle:nil];
UINavigationController *modalNavController = [[UINavigationController alloc] initWithRootViewController:newReview];
// This is intended to be presented in another view controller class
modalNavController.navigationBar.barStyle = UIBarStyleDefault;  
[self.parentViewController presentModalViewController:modalNavController animated:YES]; 
[modalNavController release];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这样的小城市 2024-10-01 13:16:33

是自子类化 UIViewController 还是其他东西?尽管我通常不使用笔尖,但我已经成功地使用导航控制器完成了视图。看看是否先推送视图成功,然后尝试呈现ModalView。

我还建议使用委托方法来实现这一点。尽管对于您正在做的事情来说不是必需的,但您会发现以后遇到的问题会更少,并且可能被认为是“正确”的做事方式。

Is self subclassing UIViewController or something else? I have successfully done a view with a nav controller this way although I don't usually do it with a nib. See if you have success with pushing the view first and then try to presentModalView.

Also I recommend using the delegate method of implementing this. Although not necessary for what you are doing you will find you will run into less problems later and is probably considered the "correct" way of doing things.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文