iPhone - 使用子视图中的按钮更改导航控制器的视图
我有一个带有根视图的导航控制器。 根视图包含按钮,这些按钮可以将新视图正确推送到导航控制器上。
然而,在这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当视图控制器被推送到导航控制器堆栈时,属性“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.
是的,这是因为如果您没有将该控制器推送到导航堆栈上或者没有手动设置它,那么 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.