Multi-Controller Management

Source: Internet
Author: User

UINavigationController7.8.1 Adding a sub-controller into the stack

Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] init];

Ctoneviewcontroller *one = [[Ctoneviewcontroller alloc] init];

Method One

[Nav Pushviewcontroller:one Animated:yes];

Method Two

[Nav Addchildviewcontroller:one];

Method Three

Nav.viewcontrollers = @[one];

Method Four

[Nav Showviewcontroller:one Sender:nil];

7.8.2 Sub-controller out of stack

Method One: Undo the current stack top controller and return to the previous controller

[Self.navigationcontroller Popviewcontrolleranimated:yes];

Method Two: Poptoviewcontroller revocation to the specified controller, only transfer the controller in the stack

Cttwoviewcontroller *VC = self.navigationcontroller.viewcontrollers[1];

[Self.navigationcontroller POPTOVIEWCONTROLLER:VC Animated:yes];

Method Three: Return directly to the stack bottom controller

[Self.navigationcontroller poptorootviewcontrolleranimated:yes];7.8.3 Navigationitem created

Uibarbuttonitem *buttonitem1 = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemplay target : selfaction: @selector (back:)];

Uibarbuttonitem *buttonitem2 = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "Zhongguo"] style: Uibarbuttonitemstyledone target:self Action: @selector (back:)];

Uibarbuttonitem *buttonitem3 = [[Uibarbuttonitem alloc] initwithtitle:@ "Back" Style:uibarbuttonitemstyledone Target: Selfaction: @selector (back:)];

7.8.4 Leftbarbuttonitems Create

Self.navigationItem.leftBarButtonItem = buttonItem1;

Self.navigationItem.leftBarButtonItems = @[buttonitem1, buttonItem2, buttonItem3];

7.8.5 Backbarbuttonitem Create

Passing parameters

7.9 UIStoryboardSegue1. Three properties of Segue

@property (nonatomic, readonly) nsstring *identifier;//unique identity

@property (nonatomic, readonly) ID sourceviewcontroller;//source Controller

@property (nonatomic, readonly) ID destinationviewcontroller;//target Controller

2. Segue is divided into manual type and automatic type, in the storyboard operation, the button is directly connected to the controller is automatic type, the controller is connected to the Controller manual type. Regardless of need to jump, with automatic type segue. After the condition is judged, we need to jump, with manual type segue. 3. Manual Segue call 1) First you need to name the identifier of the manual segue in Storyboady

2) Then call the following method:

[Self performseguewithidentifier:@ "login2contacts" sender:nil];

4. Whether it is manual type segue, or automatic type segue, the Prepareforsegue method is called before execution, we carry out a value between 2 controllers in this method.

Direct Assignment

-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender

{

Ctcontactstableviewcontroller *contact = Segue.destinationviewcontroller;

Contact.navigationItem.title = [NSString stringwithformat:@ "%@ 's Address Book", Self.textAccount.text];

}

The current controller becomes the proxy for the target controller after calling the Prepareforsegue method before performing a jump

-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender

{

Ctaddviewcontroller * Addviewcontroller = (Ctaddviewcontroller *) Segue.destinationviewcontroller;

Addviewcontroller.delegage = self;

}

Implement the method in the target controller agent to get the data and trigger the appropriate action

-(void) Addviewcontrollerbtnsave: (Ctaddviewcontroller *) Addviewcontroller

{

Ctcontact *contact = addviewcontroller.contact;

[Self.contacts Addobject:contact];

}

If you need to jump to the page, do some action, you can customize the navigation controller rewrite push or Pop method (override this method, you can also cancel some unwanted effects), or as a navigation controller agent, listen to the Jump method.

-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Didshowviewcontroller: ( uiviewcontroller*) Viewcontroller animated: (BOOL) animated

-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: ( uiviewcontroller*) Viewcontroller animated: (BOOL) animated

Multi-Controller Management

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.