PresentModalViewController 和 navigationController
我想知道
[selfpresentModalViewController:controlleranimated:YES];
之间的区别,
[self.navigationController pushViewController:controller animated:YES];
我已经使用了两者,但仍然不知道或注意到区别。什么时候应该使用其中之一?
谢谢..
I want to know the differences between the
[self presentModalViewController:controller animated:YES];
and
[self.navigationController pushViewController:controller animated:YES];
I have used both but still do not know or noticed the difference. when should use one of them ?
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本区别:
pushViewController
仅适用于导航控制器presentModalViewController
适用于所有视图控制器navigationController 是
UINavigationController
的实例,由导航堆栈中的所有控制器 (UIViewController
) 使用。Basic difference :
pushViewController
only works in navigation controllerspresentModalViewController
works for all view controllersnavigationController is the instance of your
UINavigationController
, which is used by all the controller in your navigation stack (UIViewController
).呈现模态视图是在另一个视图之上呈现一个视图。您执行这些通常是为了需要以独立的方式开始和完成的“任务”。进一步阅读苹果开发者指南上的模态视图。
如果应用程序中有导航的逻辑需求,则将视图推送到导航控制器是不同的。比如说 iDevices 的设置应用程序中的向下钻取表,其中有主要设置,然后您可以向下钻取到子设置等。
无论您的问题是什么,如果它们是概念性的和通用的,那么我强烈建议您在谷歌上搜索“X 编程指南”将带您进入正确的 Apple 编程指南:) X = 您案例中的视图控制器
http://developer.apple.com/library/ios/#featuredarticles /ViewControllerPGforiPhoneOS/Introduction/Introduction.html
Presenting a modal view is presenting a view on top of another view. You perform those typically for "tasks" that need to be started and completed in a self contained way. Read further on modal views on the apple developer guides.
Pushing a view on to the navigation controller is different where there is a logical need for navigation in the app. Say a drill down table as in the setting app of the iDevices, where there are main settings then you drill down to sub settings etc.
Whatever your questions are, if they are conceptual and generic as this I'd strongly advise you to google up "X programming guide" which will take you to the proper Apple programming guide :) X = view controller in your case
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
如果基类有它自己的 NavigationController 那么你可以写:
如果你的基类只有 UIViewController 那么使用:
现在,MyViewController 有导航,所以你可以通过在 MyViewController 中编写如下函数来推送另一个 viewController。
if base class has it's own NavigationController then you can write:
if your base class has only UIViewController then use:
now, MyViewController has navigation so you can -- Push -- another viewController by writing function as bellow in MyViewController.