At last:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvchjlx2vtaw5lbnq=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Main.storyboard
BeyondViewController.h
beyondviewcontroller.h// 16_ Controller switching mode 1_modal_ by code//// Created by beyond on 14-7-30.// Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface beyondviewcontroller:uiviewcontroller// Hint welcome who who @property (weak, nonatomic) Iboutlet UILabel *welcomelabel; @property (weak, nonatomic) Iboutlet UIButton * WANTLOGINBTN; @property (weak, nonatomic) Iboutlet UIButton *wantlogoutbtn;//Click on the login button on the Beyondviewcontroller interface, Switch to BeyondLoginViewController.h for input password account login-(ibaction) Wantlogin: (UIButton *) sender;-(ibaction) Wantlogout: ( UIButton *) sender; @end
Beyondviewcontroller.m
beyondviewcontroller.m//16_ Controller Switching mode 1_modal_ by code////Created by Beyond on 14-7-30.//Copyright (c) 2014 Com.bey Ond. All rights reserved./* Controller switch 3 ways: 1,modal (modal dialog, the new controller from the bottom up, cover the back of the Controller) (many other can see Luo Yunbin of the < gallstone in-windows environment 32-bit assembly language programming > Chapter 5.4 dialog box) through the code to implement the switch through the storyboard implementation of the switch 2,push through the Uinavigationcontroller management of the stack implementation from the right to the left to expand, pop up a new controller (at the top of the stack), involving the main content : The title of the pass-through navigation bar customizing the pre-jump verification, typically such as the client check 3,uitabbarcontroller before the login jump is managed in a parallel way View Controller 4, define the container yourself, similar to the drawer effect (right slide, popup left sidebar) */#import "BeyondViewController.h" #import "BeyondLoginViewController.h" @interface Beyondviewcontroller () <BeyondLoginViewControllerDelegate,UIActionSheetDelegate> @end @implementation beyondviewcontroller-(void) viewdidload{[super Viewdidload];} Click the login button on the Beyondviewcontroller interface to switch to BEYONDLOGINVIEWCONTROLLER.H for input password account login-(ibaction) Wantlogin: (UIButton * Sender {//want to switch to the Beyondloginviewcontroller controller by modal in code, you must create an instance object, the coupling is too strong ~ Beyondloginviewcontroller *loGinviewctrl = [[Beyondloginviewcontroller alloc]init]; The proxy setting for Loginviewctrl is the current controller, because, in the next control (Loginviewctrl), after the user has entered the user name and password, the proxy's Dosomethingwithusername method is invoked, Send a message to its proxy object (that is, the current controller), which is the user name to pass over to-loginviewctrl.delegate = self; Key, code, all controllers have this method, show [self Presentviewcontroller:loginviewctrl animated:yes completion:^{NSLog (@ "Beyondlogin control The system-appears "); }];} Implement the Proxy method in the next controller, because in the next controller (Loginviewctrl), after the user has entered the user name and password, the agent's Dosomethingwithusername method is called, to its proxy object (that is, the current controller) Send a message, the number of references is to pass over the user name ~-(void) Dosomethingwithloginname: (NSString *) username{username = [NSString stringwithformat:@] Welcome back:%@ ", username]; _welcomelabel.text = Username; Disable login button _wantloginbtn.enabled = NO; _wantlogoutbtn.enabled = YES;} -(Ibaction) Wantlogout: (UIButton *) sender{uiactionsheet *actionsheet = [[Uiactionsheet alloc]initwithtitle:@] ok to log off? " Delegate:self cancelbuttontitle:@ "Cancel" destructivebuttontitle:@ "OK" otherbuttontitles:nil, nil]; [Actionsheet ShowInView:self.view];} #pRagma Mark-actionsheet Proxy Method-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (NSInteger) buttonindex{NSLog (@ "button index:%d", buttonindex); Determine if the logoff index is 0 if (Buttonindex = = 0) {//Logoff _wantloginbtn.enabled = yes; _wantlogoutbtn.enabled = NO; _welcomelabel.text = @ ""; }//Cancel index is 1 doNothing} @end
Protocol
BeyondLoginViewControllerDelegate.h
beyondloginviewcontrollerdelegate.h// 16_ Controller switching mode 1_modal//// Created by beyond on 14-7-30.// Copyright (c) 2014 Com.beyond. All rights reserved.//#import <Foundation/Foundation.h> @protocol beyondloginviewcontrollerdelegate < nsobject>-(void) Dosomethingwithloginname: (NSString *) Username; @end
Beyondloginviewcontroller.xib
BeyondLoginViewController.h
beyondloginviewcontroller.h// 16_ Controller switching mode 1_modal//// Created by Beyond on 14-7-30.// Copyright (c) Com.beyond 2014. All rights reserved.//#import <UIKit/UIKit.h> #import "BeyondLoginViewControllerDelegate.h" @interface beyondloginviewcontroller:uiviewcontroller//ID type of proxy (weak weak reference), the method of invoking the agent, the name of the user entered in this controller, through the parameters passed to the agent for their use of @property ( Nonatomic,weak) ID <BeyondLoginViewControllerDelegate> delegate; @property (weak, nonatomic) Iboutlet Uitextfield *username; @property (weak, nonatomic) Iboutlet Uitextfield *password;//submit username and password-to the server ( Ibaction) Submit: (UIButton *) sender;//Click Back button to return to the previous controller-(ibaction) Backtohome: (Uibarbuttonitem *) sender; @end
Beyondloginviewcontroller.m
beyondloginviewcontroller.m//16_ Controller Switching mode 1_modal////Created by Beyond on 14-7-30.//Copyright (c) 2014 Com.beyon D. All rights reserved.//#import "BeyondLoginViewController.h" #import "BeyondViewController.h" #import " BeyondLoginViewControllerDelegate.h "@interface Beyondloginviewcontroller () @end @implementation beyondloginviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [ Super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;} -(void) viewdidload{[Super Viewdidload]; Set Password box to asterisk _password.securetextentry = YES;} Click Back button to return to the previous controller-(ibaction) Backtohome: (Uibarbuttonitem *) sender{//Key code, close itself this modal modal dialog [self DISMISSVIEWC Ontrolleranimated:yes completion:^{NSLog (@ "Beyondlogin controller, disappeared"); }];} Submit User name and password-(ibaction) to server submission: (UIButton *) Sender {//As JS form verification if (_username.text.length = = 0 | | _pas Sword.teXt.length = = 0) {//<# (id<uiactionsheetdelegate>) #> uiactionsheet *actionsheet = [[UIActionShee] T alloc]initwithtitle:@ "Please enter user name and password" Delegate:nil cancelbuttontitle:@ "Cancel" destructivebuttontitle:@ "red Warning" otherbuttontitles:@ "Other button", nil]; Like toast, manual display [Actionsheet ShowInView:self.view]; return directly; }//Pass the data to the previous controller/////mode 1, the coupling is too strong, directly get the one that pops up (previous) controller Beyondviewcontroller *PREVC = (beyondviewcontroller *) Self.presentingviewcontroller; This allows you to set the label of the previous controller preVC.welcomeLabel.text = _username.text; [Self dismissviewcontrolleranimated:yes completion:nil]; */////////2, using the proxy, the method of invoking the proxy, and the current controller input user name, as a reference, passed to the agent in this method, for the agent to use [Self.delegate Dosomethingwithloginname:_usernam E.text]; [Self Dismissviewcontrolleranimated:yes completion:nil];} @end
Modal modal dialog box--------implemented by storyboard mode
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
ios_16_ Switch Controller _modal_ code method