iPhone - 使用子视图中的按钮更改导航控制器的视图

发布于 2024-12-10 17:05:43 字数 520 浏览 0 评论 0原文

我有一个带有根视图的导航控制器。 根视图包含按钮,这些按钮可以将新视图正确推送到导航控制器上。

然而,在这个 rootview 上,我也有子视图(它是一个滚动预览,如 appStore 图像,由 3 个 UIview 项目组成的视图)。在这些 UIView 上,有一个按钮,我想更改 rootview 导航控制器,就像其他按钮一样。

目前,它已构建并运行,但新视图尚未推送。有什么想法吗?

单击 ScrollItem 按钮上的方法:

MyViewController *newView = [[MyViewController alloc] initWithNibName:@"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];  

...我想这是因为 self 没有导航控制器,但 rootview 有。

谢谢!!

I have a navigation controller with a rootview.
The rootview contains buttons, which push new views onto the navigation controller correctly.

However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.

At the moment, it builds and runs, but the new view is not pushed. Any ideas?

Click method on on the ScrollItem button:

MyViewController *newView = [[MyViewController alloc] initWithNibName:@"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];  

... i guess it is because, self doesn't have a navigation controller, but the rootview does.

Thanks!!

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

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

发布评论

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

评论(2

雪落纷纷 2024-12-17 17:05:43

仅当视图控制器被推送到导航控制器堆栈时,属性“navigationController”才会在视图控制器中设置。您的第二个视图是推送视图控制器的子视图,这意味着该属性为 NULL,并且如果您尝试将内容推送到它,则不会执行任何操作。

The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.

郁金香雨 2024-12-17 17:05:43

是的,这是因为如果您没有将该控制器推送到导航堆栈上或者没有手动设置它,那么 self.navigationController 将会为零。

因此,您只需要引用 rootViewController.navigationController ,然后 [navigationController PushViewController:newViewAnimated:YES]; 就可以完美工作。

Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.

So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.

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