The Navigation controller for iOS

Source: Internet
Author: User
Tags set background

Uinavigationcontroller is the primary tool for building tiered applications, primarily in the form of stacks to implement views. Any type of view controller can be placed on the stack. When designing a navigation controller, you need to specify the root view, which is the first view that the user sees. The root view controller is the first view controller that is pushed into the stack by a navigation controller. When the user views the next attempt, a new view controller is added to the stack, and the view it controls is displayed to the user. We can use the navigation buttons to manipulate the layered application, which controls the push-in or roll-out of the view.

1, the controller added to the navigation controller commonly used methods

   // Create a View controller    Jrviewcontroller * vc=[[Jrviewcontroller alloc] init];           // Create a navigation controller, and use the above controller as the root controller    for the navigation controller Uinavigationcontroller * navc=[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC];         // sets the current Navigation Controller Settings window's root view controller SELF.WINDOW.ROOTVIEWCONTROLLER=NAVC;

2, so we put Jrviewcontroller as the current navigation controller root controller, below we enter into Jrviewcontroller, and add a title and button code as follows

    //Set BackgroundSelf.view.backgroundcolor=[Uicolor Redcolor]; //Set Titleself.title=@"Boutique"; //Add buttonUIButton * Button=[[uibutton Alloc] Initwithframe:cgrectmake (0,0, -, $)]; Button.backgroundcolor=[Uicolor Blackcolor]; [Button Settitle:@"Push"Forstate:uicontrolstatenormal]; Button.center=Self.view.center;    [Button addtarget:self action: @selector (Pushvcnew) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button];

As follows:

  3, we will proceed to the view controller between the jump

Navigation Controller management view controller mainly to take the pressure stack and the way out of the stack, let's feel how to switch, add the button above we added the Click event, below we re-click the Event Trigger method:

-(void) pushvcnew{        // Initialize a second controller    Secondviewcontroller * sec=[[ Secondviewcontroller alloc] init];     // Switch to another view controller     [Self.navigationcontroller pushviewcontroller:sec animated:yes];    }

As follows:

After the stack enters the response is out of the stack, how to go back to the stack, we rewrite the second controller return method, call the controller's Popviewcontrolleranimated method can be

-(void) popvc{    [Self.navigationcontroller popviewcontrolleranimated:yes];}

5. Navigation buttons

//1 Construction MethodsUibarbuttonitem * Item1=[[uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@"BT1"] Style:uibarbuttonitemstyleplain target:self action: @selector (Leftclick)]; //2 Customizing ViewsUIButton * Button=[[uibutton Alloc] Initwithframe:cgrectmake ( -, -, -, +)]; Button.backgroundcolor=[Uicolor Redcolor]; [Button Settitle:@"Hello"Forstate:uicontrolstatenormal]; Uibarbuttonitem* item2=[[Uibarbuttonitem alloc] Initwithcustomview:button]; //3 Add to current Navigationitemself.navigationitem.leftbarbuttonitem=item2; Self.navigationItem.rightBarButtonItem=item1; //4 Add titleUILabel * Label=[[uilabel Alloc] Initwithframe:cgrectmake (0,0, -, +)]; Label.text=@"Navigation Controller"; Label.textcolor=[Uicolor Redcolor];self.navigationitem.titleview=label;

As follows

6, toolbar toolbar, each navigation controller has a toolbar, default is hidden state, below we will open the toolbar and use it.

//Open Toolbarself.navigationcontroller.toolbarhidden=NO; //Define toolbar Add buttonUibarbuttonitem * item1=[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcancel target:self action: @selector (    PUSHVC)]; Uibarbuttonitem* item2=[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemsave target:self action: @selector (    PUSHVC)]; Uibarbuttonitem* item3=[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitembookmarks target:self action:@    Selector (PUSHVC)]; Uibarbuttonitem* item4=[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemorganize target:self action:@    Selector (PUSHVC)]; Uibarbuttonitem* item5=[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self action: @selector (    PUSHVC)]; Uibarbuttonitem* item6=[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemstop target:self action: @selector (         PUSHVC)]; Uibarbuttonitem* item7=[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:self action:@      Selector (PUSHVC)]; Uibarbuttonitem* item8=[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:self action:@    Selector (PUSHVC)]; Item8.width= -; //Add a button to the toolbar[Email protected] [ITEM1,ITEM8,ITEM2,ITEM8,ITEM3,ITEM8,ITEM4,ITEM7,ITEM5,ITEM8,ITEM6];

As follows:

Jerry Education
Source:http://www.cnblogs.com/jerehedu/
Copyright Notice: The copyright of this article belongs to cigarettes DeskJerry EducationSection Technology Co., Ltd. and blog Park are shared, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
Technical Consultation:

The Navigation controller for iOS

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.