创建三个类
然后我们在BasicViewController .m文件中push一个viewController:
SecondViewController *svc = [SecondViewController new];
[self.navigationController [color=red]pushViewController[/color]:svc animated:true];
在SecondViewController.m文件中pop出viewController:
[self.navigationController [color=red]popViewControllerAnimated[/color]:true]
问题就来了,
[color=red]push和pop是同一个viewController,那为什么用self.navigationController 就可以知道了[/color]
其中在AppDelegate.m:
等价于
分配内存如图
[img]http://dl2.iteye.com/upload/attachment/0092/2147/8a25cf60-3168-3f11-baff-ed5b6c228269.jpg[/img]
BasicViewController : UIViewController
SecondViewController : UIViewController
ThirdViewController : UIViewController
然后我们在BasicViewController .m文件中push一个viewController:
SecondViewController *svc = [SecondViewController new];
[self.navigationController [color=red]pushViewController[/color]:svc animated:true];
在SecondViewController.m文件中pop出viewController:
[self.navigationController [color=red]popViewControllerAnimated[/color]:true]
问题就来了,
[color=red]push和pop是同一个viewController,那为什么用self.navigationController 就可以知道了[/color]
其中在AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
BasicViewController *basicViewController = [BasicViewController new];//实例化内存后,_parentViewController-->nil
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:basicViewController];
// self.window.rootViewController = basicViewController.parentViewController;
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
等价于
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
BasicViewController *basicViewController = [BasicViewController new];//实例化内存后,_parentViewController-->nil
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:basicViewController];
self.window.rootViewController = basicViewController.parentViewController; //不可以注释上一句,因为上一句是为_parentViewController实例化
// self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
分配内存如图
[img]http://dl2.iteye.com/upload/attachment/0092/2147/8a25cf60-3168-3f11-baff-ed5b6c228269.jpg[/img]