Snail-ui Learning Navigation View Controller Uinavigationcontroller (System)

Source: Internet
Author: User

Background

Have a root view controller and then jump to the first interface the first interface can be returned to the root view or jump to the second view the second view can be returned directly to the root view

New three Viewcontroller Rootviewcontroller Firstviewcontroller Secondviewcontroller

First write in APPDELEGATE.M

#import "WJJAppDelegate.h" #import "WJJRootViewController.h" @implementation wjjappdelegate-(BOOL) Application: ( UIApplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) launchoptions{    Self.window = [[ UIWindow alloc] Initwithframe:[[uiscreen mainscreen] bounds]];    Override point for customization after application launch.    Self.window.backgroundColor = [Uicolor whitecolor];    Wjjrootviewcontroller * Rootviewcontroller = [[Wjjrootviewcontroller alloc] init];    Create a navigation controller and add the root created above to the navigation controller    Uinavigationcontroller * nav = [[Uinavigationcontroller alloc]                                    Initwithrootviewcontroller:rootviewcontroller];    Self.window.rootViewController = nav;    [Self.window makekeyandvisible];    return YES;}

Then the write-down button in Rootviewcontroller will go to Firstviewcontroller

-(void) viewdidload{    [Super viewdidload];//do any additional setup after loading the view.    [Self Createbutton];} Create a button click to enter write an interface-(void) createbutton{    UIButton * Nextbutton = [UIButton Buttonwithtype:uibuttontypesystem];    Nextbutton.frame = CGRectMake (+, +, +);    [Nextbutton settitle:@ "Next page" Forstate:uicontrolstatenormal];    [Nextbutton addtarget:self Action: @selector (NextPage) forcontrolevents:uicontroleventtouchupinside];    [Self.view Addsubview:nextbutton];} -(void) nextpage{    wjjfirstviewcontroller * first = [[Wjjfirstviewcontroller alloc] init];    Use the Push method to enter the next interface when you return to the previous interface, all interfaces are not lost, but are pressed into the stack    //followed by present the Jump interface is different    [Self.navigationcontroller Pushviewcontroller:first Animated:yes];}
Click on the left button in Firstviewcontroller to go back to the first page, click the right button to go to the next

-(void) viewdidload{[Super viewdidload];//do any additional setup after loading the view.    Self.view.backgroundColor = [Uicolor Redcolor]; On the left and right side of the navigation controller, customize the return key, next page key [self createbarbuttonitem];}    -(void) createbarbuttonitem{UIButton * Popbutton = [UIButton Buttonwithtype:uibuttontypesystem];    If the left and right side of the navigation bar, the custom button is not related to X, Y is only related to the width of height popbutton.frame = cgrectmake (0, 0, 50, 20);    Set title [Popbutton settitle:@ "return" forstate:uicontrolstatenormal];    [Popbutton addtarget:self Action: @selector (back) forcontrolevents:uicontroleventtouchupinside];    Create a custom navigation bar button with the pop button Uibarbuttonitem * item = [[Uibarbuttonitem alloc] Initwithcustomview:popbutton];            Change the navigation bar back button to our custom Self.navigationItem.leftBarButtonItem = Item;    UIButton * pushbutton = [UIButton Buttonwithtype:uibuttontypesystem];    If the left and right side of the navigation bar, the custom button is not related to X, Y is only related to the width of height pushbutton.frame = cgrectmake (0, 0, 50, 20);    Set title [Pushbutton settitle:@ "Next" forstate:uicontrolstatenormal]; [Pushbutton Addtarget:self Action: @selector (NextPage) forcontrolevents:uicontroleventtouchupinside];    Create a custom navigation bar button with the push button Uibarbuttonitem * item2 = [[Uibarbuttonitem alloc] Initwithcustomview:pushbutton];        Let the right button of the navigation bar change to our custom Self.navigationItem.rightBarButtonItem = item2;    }-(void) nextpage{Wjjsecondviewcontroller * second = [[Wjjsecondviewcontroller alloc] init]; [Self.navigationcontroller Pushviewcontroller:second animated:yes];} -(void) back{//pop This view into the stack so that the previous interface is displayed [Self.navigationcontroller Poptorootviewcontrolleranimated:yes];}

Then, click the button in the Secondviewcontroller to return to the homepage

-(void) viewdidload{    [Super viewdidload];//do any additional setup after loading the view.    Self.view.backgroundColor = [Uicolor graycolor];    [Self Createtorootbutton];} Create a new button click Back Home-(void) createtorootbutton{    UIButton * Torootbutton = [UIButton buttonwithtype: Uibuttontypesystem];    Torootbutton.frame = CGRectMake (+, +, +);    [Torootbutton settitle:@ "Home" forstate:uicontrolstatenormal];    [Torootbutton addtarget:self Action: @selector (Torootpage) forcontrolevents:uicontroleventtouchupinside];    [Self.view Addsubview:torootbutton];} Click the button to return to the first page there are two ways-(void) torootpage{    //First Direct return to the home page    //[self.navigationcontroller Poptorootviewcontrolleranimated:yes];        The second is because these view controllers are stack-and-stack operations, so there is an array of view controllers in the view controller The first page is labeled 0    [Self.navigationcontroller poptoviewcontroller: Self.navigationcontroller.viewcontrollers[0] animated:yes];    }

Home


First page

A second page


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Snail-ui Learning Navigation View Controller Uinavigationcontroller (System)

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.