IOS_18 _ controller switchover _ NavigationController_push _ data transfer, ios navigation Controller
Finally:
Storyboard:
BeyondViewController. h
//// BeyondViewController. h // 18 _ controller switchover _ navigation_push _ using storyboard // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface BeyondViewController: UIViewController // button on the left of NavigationItem @ property (weak, nonatomic) IBOutlet UIBarButtonItem * refreshBtn; // the button on the Right of NavigationItem @ property (weak, nonatomic) IBOutlet UIBarButtonItem * wantToLoginBtn; // click the button on the left of NavigationItem to refresh the event to the initial state-(IBAction) refresh :( UIBarButtonItem *) sender; @ end
BeyondViewController. m
//// BeyondViewController. m // 18 _ controller switchover _ navigation_push _ using storyboard // 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 = @ "Homepage"; self. wantToLoginBtn. enabled = YES; self. refreshBtn. enabled = NO;} @ end
LoginViewController. h
//// LoginViewController. h // 18 _ controller switchover _ navigation_push _ using storyboard // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface LoginViewController: UIViewController // username input box @ property (weak, nonatomic) IBOutlet UITextField * username; // password input box @ property (weak, nonatomic) IBOutlet UITextField * password; // enter the user name and password, click the logon button-(IBAction) loginBtnClick :( UIButton *) sender; // click the button on the left of NavigationItem to return to the previous controller-(IBAction) backToHome :( UIBarButtonItem *) sender; @ end
LoginViewController. m
//// LoginViewController. m // 18 _ controller switchover _ navigation_push _ using storyboard // 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: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self ;} # pragma mark-Navigation // preparations before you jump to the next Navigation subcontroller through the segue! Here we pass the data to the destination controller-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) username {// to obtain the destination controller, use [segue destinationViewController]. // here, you can pass data to the next controller. // this parameter is the NSLog (@ "prepare for segue ---- % @", username) of the data to be passed ); // get the target controller to be redirected through destinationViewController of segue and pass 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 the username and password, and click the logon button-(IBAction) loginBtnClick :( UIButton *) sender {// robust to judge if (_ username. text. length = 0 | _ password. text. length = 0) {UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle: @ "Enter the account and password" delegate: nil cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "understand" otherButtonTitles: @ "other", nil]; [sheet showInView: self. view]; [_ username becomeFirstResponder]; return;} // enter the correct password and account, and then jump to the 3rd controllers // self. navigationController pushViewController: <# (UIViewController *) #> animated: <# (BOOL) #> // jump to self by connecting to the server using the seue. the next sub-controller in the navigationController container, and the parameter (user name) is passed, the parameter will be passed to the self prepareForSegue method, and then passed to the next controller (destination) [self authentication mseguewithidentifier: @ "segue_loginSuccess" sender: _ username. text];} // click the button on the left of NavigationItem to return to the previous controller, that is, the homepage-(IBAction) backToHome :( UIBarButtonItem *) sender {[self. navigationController popViewControllerAnimated: YES];} @ end
NanaViewController. h
//// NanaViewController. h // 18 _ controller switchover _ navigation_push _ using storyboard // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ interface NanaViewController: UIViewController // the button on the Right of NavigationItem. Welcome to the slogan @ property (weak, nonatomic) IBOutlet UIBarButtonItem * item_nanaSay; // click the button on the left of NavigationItem to return to, that is, the first controller, and the data is taken over-(IBAction) backToHome :( UIBarBu TtonItem *) sender; // used only to receive transmitted data ~ @ Property (nonatomic, copy) NSString * username; @ end
NanaViewController. m
//// NanaViewController. m // 18 _ controller switchover _ navigation_push _ using storyboard // 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 *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;} // return to the home page, that is, the first controller, and bring the data to the past-(IBAction) backToHome :( UIBarButtonItem *) sender {// get the first controller BeyondViewController * firstVC = [self. navigationController. viewControllers firstObject]; // [self. navigationController. viewControllers objectAtIndex: N-2]; // n for the most recent index // Add the data NSString to be passed * str = [NSString stringWithFormat: @ "Welcome % @ back ", _ username]; firstVC. navigationItem. title = str; firstVC. wantToLoginBtn. enabled = NO; firstVC. refreshBtn. enabled = YES; // pop to the first controller [self. navigationController popToViewController: firstVC animated: YES];} @ end
======================================
**************
I am a split line
**************
======================================
Implementation of push, using code:
BeyondAppDelegate. h
/// BeyondAppDelegate. h // 18 _ controller switchover _ navigationCtrl_push _ code method // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import <UIKit/UIKit. h> @ class BeyondViewController; @ interface BeyondAppDelegate: UIResponder <UIApplicationDelegate> @ property (strong, nonatomic) UIWindow * window; // Add a member property controller @ property (nonatomic, strong) BeyondViewController * viewController for the proxy of the application; @ end
BeyondAppDelegate. m
/// BeyondAppDelegate. m // 18 _ controller switchover _ navigationCtrl_push _ code method // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondAppDelegate. h "# import" BeyondViewController. h "@ implementation BeyondAppDelegate-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {================================= compare with the original self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // Override point for customization after application launch. // instantiate a BeyondViewController self for the member attribute of the application proxy. viewController = [[BeyondViewController alloc] initWithNibName: @ "BeyondViewController" bundle: nil]; // set BeyondViewController to the rootViewController self of the window. window. rootViewController = self. viewController; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES; ====================================== compare the original self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // instantiate a BeyondViewController controller self for the member attribute of the application proxy. viewController = [[BeyondViewController alloc] initWithNibName: @ "BeyondViewController" bundle: nil]; // create a navigation controller, set the Controller at the bottom of the stack to BeyondViewController UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController: self. viewController]; // Finally, set the navigation controller to the rootViewController self of the window. window. rootViewController = navi; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES ;}@ end <pre>
BeyondViewController. m
//// BeyondViewController. m // 18 _ controller switchover _ navigationCtrl_push _ code method // Created by beyond on 14-7-31. // Copyright (c) 2014 com. beyond. all rights reserved. /* navigation Controller method summary: 1. Create a navigation controller. In the App proxy method, // create a navigation controller, set the Controller at the bottom of the stack to BeyondViewController UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController: self. viewController]; 2. Stack form management self. navigationController. viewControllers 3, the pressure stack is Jump to the next controller [self. navigationController pushViewController: loginVC animated: YES]; 4. The output stack is returned. The controller is displayed from the stack [self. navigationController popToRootViewControllerAnimated: YES]; [self. navigationController popViewControllerAnimated: YES]; [self. navigationController popToViewController: <# (UIViewController *) #> animated: <# (BOOL) #>]; 5. The navigation bar displays the title, left Item, right item, the returned text in the returned item is determined by the last controller ??? Self. title is self. navigationItem. title 6: Obtain the stack top controller self. navigationController. topViewController */# import "BeyondViewController. h "# import" LoginViewController. h "@ interface BeyondViewController () @ end @ implementation BeyondViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // set the top title self. navigationItem. title = @ "Homepage"; // set the button on the right and click event self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "Next" style: UIBarButtonItemStyleBordered target: self action: @ selector (nextBtnClick)];} // click the next one, go to the next controller-(void) nextBtnClick {// instantiate, add the next controller, push it to the parent container, and animated jump to LoginViewController * loginVC = [[LoginViewController alloc] init]; // you can also get the container controller, that is, the navigation controller [self. parentViewController]; [self. navigationController pushViewController: loginVC animated: YES];} @ end
BeyondViewController. xib
2nd controllers. m
//// LoginViewController. m // 18 _ controller switchover _ navigationCtrl_push _ code method // 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-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // set the top title self. navigationItem. title = @ ""; // set the display text self of the return button. navigationItem. backBarButtonItem. title = @ "previous"; // set the button on the right of the top and add the listening event UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithTitle: @ "Next" style: UIBarButtonItemStyleBordered target: self action: @ selector (rightBtnClick)]; self. navigationItem. rightBarButtonItem = item;} // response to the top right click-(void) rightBtnClick {// instantiate, 3rd controllers, push to the top of the stack // instantiate, next controller, add it to the parent container by push, and animated jump to NanaViewController * nanaVC = [[NanaViewController alloc] init]; // you can also get the container controller, that is, the navigation controller [self. parentViewController]; [self. navigationController pushViewController: nanaVC animated: YES];} @ end