为什么从 UITabBarController 子视图推送时 self.navigationController 为 NULL

发布于 2024-11-27 11:42:28 字数 1021 浏览 1 评论 0原文

这就是我正在做的事情。我有一个带有 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 技术交流群。

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

发布评论

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

评论(2

吲‖鸣 2024-12-04 11:42:28

不支持在 UINavigationController 中嵌入 UITabBarController。 Apple 有一个仔细的容器视图控制器层次结构,并且 UITabBarController 必须是其视图控制器层次结构的根。

此外,正如 Joe 指出的那样,您的视图不属于导航控制器;您的视图不属于导航控制器。它们属于标签栏控制器,因此它们的 navigationController 属性未设置。

Embedding a UITabBarController inside a UINavigationController is not supported. Apple has a careful hierarchy of container view controllers, and a UITabBarController 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.

め七分饶幸 2024-12-04 11:42:28

模式视图控制器不属于 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:

Discussion
Only returns a navigation controller if the view controller
is in its stack. This property is nil if a navigation controller
cannot be found.

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