为什么从 UITabBarController 子视图推送时 self.navigationController 为 NULL
这就是我正在做的事情。我有一个带有 5 个选项卡的 tabBarControllerOne
。单击其中一个选项卡时,我会呈现一个模式视图控制器,其中有一个导航栏和一个 TabBarControllerTwo
(带有 3 个选项卡)。这三个选项卡是这里需要关注的问题。
在 tabBarController
的第 5 个选项卡中,我将 modalViewController 显示为
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.nextTabView];
// navController.navigationBarHidden = YES;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
NSLog(@"Displauing the navcontroller before pushing %@", navController);
[self presentModalViewController:navController animated:NO];
这里,nextTabView
是一个带有 3 个选项卡的 tabBarController。观点有效。在观点中,如果我尝试类似的事情。
self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController: someController animated:YES];
// nothing works.
如果我 NSLog,它会将 self.navigationController
显示为 (null)
有人能告诉我为什么这不起作用吗?
This is what I am doing. I have a tabBarControllerOne
with 5 tabs. On clicking one of the tabs, I present a modal view controller, which has a navigationBar and a TabBarControllerTwo
(with 3 tabs). These three tabs are the matter for concern here.
In the 5th Tab of tabBarController
I show modalViewController as
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.nextTabView];
// navController.navigationBarHidden = YES;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
NSLog(@"Displauing the navcontroller before pushing %@", navController);
[self presentModalViewController:navController animated:NO];
Here, nextTabView
is a tabBarController with 3 tabs. The views work. In the views, if I try something like.
self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController: someController animated:YES];
// nothing works.
If I NSLog, it displays self.navigationController
as (null)
Can someone tell me why this is not working ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不支持在
UINavigationController
中嵌入UITabBarController
。 Apple 有一个仔细的容器视图控制器层次结构,并且UITabBarController
必须是其视图控制器层次结构的根。此外,正如 Joe 指出的那样,您的视图不属于导航控制器;您的视图不属于导航控制器。它们属于标签栏控制器,因此它们的
navigationController
属性未设置。Embedding a
UITabBarController
inside aUINavigationController
is not supported. Apple has a careful hierarchy of container view controllers, and aUITabBarController
must be the root of its view controller hierarchy.Additionally, as Joe points out, your views don't belong to the navigation controller; they belong to the tab bar controller, so their
navigationController
property is not set.模式视图控制器不属于 UINavigationController 堆栈,因此未设置该属性。您将需要使用 委托当选择某些内容时通知创建控制器,然后该控制器可以正确地将下一个控制器推入堆栈。
UIViewController 参考:
The modal view controller does not belong to a
UINavigationController
stack therefore the property is not set. You will want to use delegation to notify the creating controller when something is selected then that controller can properly push the next controller on to the stack.UIViewController Reference: