Create three classes
C + + code
- Basicviewcontroller:uiviewcontroller
- Secondviewcontroller:uiviewcontroller
- Thirdviewcontroller:uiviewcontroller
Then we push a viewcontroller in the Basicviewcontroller. m file:
Secondviewcontroller *svc = [Secondviewcontroller new];
[Self.navigationcontroller pushviewcontroller:svc animated:true];
Pop out Viewcontroller in the secondviewcontroller.m file:
[Self.navigationcontroller Popviewcontrolleranimated:true]
Here's the problem.
Push and pop are the same viewcontroller, so why use Self.navigationcontroller to know
Among them in APPDELEGATE.M:
C + + code
- -(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]; After instantiating the memory, _parentviewcontroller-->nil
- Uinavigationcontroller *navigationcontroller = [[Uinavigationcontroller alloc] Initwithrootviewcontroller: Basicviewcontroller];
- //Self.window.rootViewController = Basicviewcontroller.parentviewcontroller;
- Self.window.rootViewController = Navigationcontroller;
- [Self.window makekeyandvisible];
- return YES;
- }
Equivalent to
C + + code
- -(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]; After instantiating the memory, _parentviewcontroller-->nil
- Uinavigationcontroller *navigationcontroller = [[Uinavigationcontroller alloc] Initwithrootviewcontroller: Basicviewcontroller];
- Self.window.rootViewController = Basicviewcontroller.parentviewcontroller; //Can not comment on the previous sentence, because the previous sentence is instantiated for _parentviewcontroller
- //Self.window.rootViewController = Navigationcontroller;
- [Self.window makekeyandvisible];
- return YES;
- }
Allocating memory
IOS deep understanding of the relationship between Uinavigationcontroller and Uiviewcontroller