PresentModalViewController 和 navigationController

发布于 2024-11-02 04:45:59 字数 263 浏览 2 评论 0原文

我想知道

[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 技术交流群。

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

发布评论

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

评论(3

携君以终年 2024-11-09 04:45:59

基本区别:

pushViewController 仅适用于导航控制器

presentModalViewController 适用于所有视图控制器

navigationControllerUINavigationController 的实例,由导航堆栈中的所有控制器 (UIViewController) 使用。

Basic difference :

pushViewController only works in navigation controllers

presentModalViewController works for all view controllers

navigationController is the instance of your UINavigationController, which is used by all the controller in your navigation stack (UIViewController).

笙痞 2024-11-09 04:45:59

呈现模态视图是在另一个视图之上呈现一个视图。您执行这些通常是为了需要以独立的方式开始和完成的“任务”。进一步阅读苹果开发者指南上的模态视图。

如果应用程序中有导航的逻辑需求,则将视图推送到导航控制器是不同的。比如说 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

四叶草在未来唯美盛开 2024-11-09 04:45:59

如果基类有它自己的 NavigationController 那么你可以写:

[self.navigationController pushViewController:objMyViewController animated:YES];

如果你的基类只有 UIViewController 那么使用:

MyViewController * objMyViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:objMyViewController];
navController.navigationItem.leftBarButtonItem  = nil;  // make nil if you want
                                                        // to use it in next View
[self presentModalViewController:navController animated:YES];

现在,MyViewController 有导航,所以你可以通过在 MyViewController 中编写如下函数来推送另一个 viewController。

-(IBAction)btnNext_click {
    SecondViewController * objSecondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    [self.navigationController pushViewController:objSecondViewController animated:YES];
}

if base class has it's own NavigationController then you can write:

[self.navigationController pushViewController:objMyViewController animated:YES];

if your base class has only UIViewController then use:

MyViewController * objMyViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:objMyViewController];
navController.navigationItem.leftBarButtonItem  = nil;  // make nil if you want
                                                        // to use it in next View
[self presentModalViewController:navController animated:YES];

now, MyViewController has navigation so you can -- Push -- another viewController by writing function as bellow in MyViewController.

-(IBAction)btnNext_click {
    SecondViewController * objSecondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
    [self.navigationController pushViewController:objSecondViewController animated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文