IOS_18_ Controller Switch _navigationcontroller_push mode _ Pass Data

Source: Internet
Author: User
Tags uikit

Eventually:



Storyboard



BeyondViewController.h

  beyondviewcontroller.h//  18_ Controller switch _navigation_push_ by storyboard mode////  Created by Beyond on 14-7-31.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface beyondviewcontroller:uiviewcontroller// Navigationitem left button @property (weak, nonatomic) Iboutlet uibarbuttonitem *refreshbtn;//Navigationitem right button @property ( Weak, nonatomic) Iboutlet uibarbuttonitem *wanttologinbtn;//navigationitem left button click event Refresh to initial state-(ibaction) Refresh: ( Uibarbuttonitem *) sender; @end


Beyondviewcontroller.m


  beyondviewcontroller.m//  18_ Controller switch _navigation_push_ by storyboard mode////  Created by Beyond on 14-7-31.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h" @interface Beyondviewcontroller () @end @implementation beyondviewcontroller//Refresh to initial state-(ibaction) Refresh: (Uibarbuttonitem *) sender{    self.navigationItem.title = @ "Home";    self.wantToLoginBtn.enabled = YES;    self.refreshBtn.enabled = NO;} @end

LoginViewController.h

  loginviewcontroller.h//  18_ Controller switch _navigation_push_ by storyboard mode////  Created by beyond on 14-7-31.  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface loginviewcontroller:uiviewcontroller// User name input box @property (weak, nonatomic) iboutlet uitextfield *username;//password input box @property (weak, nonatomic) Iboutlet Uitextfield *password;//enter username and password, click the login button-(ibaction) Loginbtnclick: (UIButton *) sender;//Navigationitem left button click event  returns the previous controller-(ibaction) Backtohome: (Uibarbuttonitem *) sender; @end


Loginviewcontroller.m

loginviewcontroller.m//18_ Controller switch _navigation_push_ by storyboard mode////Created by Beyond on 14-7-31.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "LoginViewController.h" #import "NanaViewController.h" @interface Loginviewcontroller ()        @end @implementation loginviewcontroller-(void) viewdidload{[Super Viewdidload]; _password.securetextentry = YES;} -(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super Initwithnibname:nibnam    Eornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} #pragma mark-navigation//before jumping through the segue to the next navigation sub-controller, do the preparation! Here is the transfer of data to the destination controller-(void) Prepareforsegue: (Uistoryboardsegue *)    Segue Sender: (ID) username{//To get the destination controller, use [Segue Destinationviewcontroller].        Here, the data can be passed to the next controller//This parameter is the data to be passed NSLog (@ "Prepare for segue----%@", username); By Segue Destinationviewcontroller get the target controller to jump, pass the data to it nanaviewcontroller *NANAVC = [Segue DestinatIonviewcontroller];    NSString *oldtitle = NanaVC.item_nanaSay.title;    Nanavc.username = Username;    NSString *newstr = [NSString stringwithformat:@ "%@ Hello ~%@", username,oldtitle];    NanaVC.item_nanaSay.title = Newstr; }//Enter user name and password, click the login button-(ibaction) Loginbtnclick: (UIButton *) sender{//robust to determine if (_username.text.length = = 0 | | _p Assword.text.length = = 0) {Uiactionsheet *sheet = [[Uiactionsheet alloc]initwithtitle:@ "Please enter your account and password" Delegate:nil can        celbuttontitle:@ "Cancel" destructivebuttontitle:@ "understand" otherbuttontitles:@ "other", nil];        [Sheet ShowInView:self.view];        [_username Becomefirstresponder];    Return }//Enter the correct password and account, jump to 3rd controller//Self.navigationcontroller pushviewcontroller:<# (Uiviewcontroller *) #> Animat ed:<# (BOOL) #>//Through Segue connection, jump to the next sub-controller inside the Self.navigationcontroller container, and pass parameters (username), parameters will be passed to Self's preparefo The Rsegue method is then passed to the next controller (destination) [Self performseguewithidentifier:@ "segue_loginsuccess" SendeR:_username.text]; }//Navigationitem left button click event to return to the previous controller, that is, home-(Ibaction) Backtohome: (Uibarbuttonitem *) sender{[    Self.navigationcontroller Popviewcontrolleranimated:yes]; } @end

NanaViewController.h

  nanaviewcontroller.h//  18_ Controller switch _navigation_push_ by storyboard mode////  Created by Beyond on 14-7-31./ /  Copyright (c) Com.beyond 2014. All rights reserved.//#import <UIKit/UIKit.h> @interface nanaviewcontroller:uiviewcontroller// Navigationitem right button   welcome slogan @property (weak, nonatomic) Iboutlet Uibarbuttonitem *item_nanasay;// Click the button on the left of Navigationitem  to return to the home page, the first controller, and bring the data over-(ibaction) Backtohome: (Uibarbuttonitem *) sender;//only to receive the data passed over the ~ @property (nonatomic,copy) NSString * username; @end



Nanaviewcontroller.m


nanaviewcontroller.m//18_ Controller switch _navigation_push_ by storyboard mode////Created by Beyond on 14-7-31.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "NanaViewController.h" #import "BeyondViewController.h" @interface Nanaviewcontroller () @end @implementation nanaviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *)    nibbundleornil{self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;}  Go back to the home page, the first controller, and bring the data over-(ibaction) Backtohome: (Uibarbuttonitem *) Sender {//Get the first controller Beyondviewcontroller *FIRSTVC        = [Self.navigationController.viewControllers firstobject];  [Self.navigationController.viewControllers objectatindex:n-2];    N for the top index//Join the data to be passed nsstring *str = [NSString stringwithformat:@ "Welcome%@ back", _username];    FirstVC.navigationItem.title = str;    firstVC.wantToLoginBtn.enabled = NO;    firstVC.refreshBtn.enabled = YES; Pop to PageOne controller [Self.navigationcontroller POPTOVIEWCONTROLLER:FIRSTVC animated:yes];} @end



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.