IOS deep understanding of the relationship between Uinavigationcontroller and Uiviewcontroller

Source: Internet
Author: User

Create three classes

C + + code
    1. Basicviewcontroller:uiviewcontroller
    2. Secondviewcontroller:uiviewcontroller
    3. 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
  1. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
  2. {
  3. Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
  4. //Override point for customization after application launch.
  5. Basicviewcontroller *basicviewcontroller = [Basicviewcontroller new]; After instantiating the memory, _parentviewcontroller-->nil
  6. Uinavigationcontroller *navigationcontroller = [[Uinavigationcontroller alloc] Initwithrootviewcontroller: Basicviewcontroller];
  7. //Self.window.rootViewController = Basicviewcontroller.parentviewcontroller;
  8. Self.window.rootViewController = Navigationcontroller;
  9. [Self.window makekeyandvisible];
  10. return YES;
  11. }



Equivalent to

C + + code
  1. -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
  2. {
  3. Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];
  4. //Override point for customization after application launch.
  5. Basicviewcontroller *basicviewcontroller = [Basicviewcontroller new]; After instantiating the memory, _parentviewcontroller-->nil
  6. Uinavigationcontroller *navigationcontroller = [[Uinavigationcontroller alloc] Initwithrootviewcontroller: Basicviewcontroller];
  7. Self.window.rootViewController = Basicviewcontroller.parentviewcontroller; //Can not comment on the previous sentence, because the previous sentence is instantiated for _parentviewcontroller
  8. //Self.window.rootViewController = Navigationcontroller;
  9. [Self.window makekeyandvisible];
  10. return YES;
  11. }



Allocating memory

IOS deep understanding of the relationship between Uinavigationcontroller and Uiviewcontroller

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.