UINavigationController 导航结构

导航应用的创建,我们一般是通过UINavigationController  类,注意不需要子类话他, 与一般的MVC 结构类似,我们其实是在普通的MVC 结果中,多了一个控制器,这个是导航控制器

用与管理所有其他的Controller,

@property (nonatomic, strong) UINavigationController *navigationController;


- (BOOL) application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc]
initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
self.rootViewController = [[RootViewController alloc]
initWithNibName:nil
bundle:NULL];
self.navigationController =
[[UINavigationController alloc]
initWithRootViewController:self.rootViewController];
[self.window addSubview:self.navigationController.view];


return YES;
}

我们把navigationController 作为self.Window.rootView Controller 传入.  而navigationController 中有一个数组专门保存其他的控制器.

NSArray *currentControllers = self.navigationController.viewControllers;

我们可以在appDelegate 中实例化所有的这些控制器,然后出入到navigationController.viewControllers;  注意最后一个加入到数组的是当前的显示的Controller

通过加入这些控制器过程中,会在assign each ViewController's property navigationController  to this NavigationController. 也就是说每一个控制器都保留一份

导航控制器的引用. 有了这个引用我们就可以在自己的控制器里push/pop ViewController

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html


[self performSelector:@selector(pushSecondController)
withObject:nil
afterDelay:5.0f];


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

[self.navigationController popViewControllerAnimated:YES];


NSArray *currentControllers = self.navigationController.viewControllers;


[self.navigationController setViewControllers:newControllers
animated:YES];






你可能感兴趣的:(mvc,null,application,each)