IOS_16 _ controller switchover _ modal _ code mode
Finally:
Main. Hits? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcnlib2fyzdwvc3ryb25np1_vcd4kpha + pgltzybzcm9" http://www.2cto.com/uploadfile/Collfiles/20140731/2014073109171811.png "alt =" \ ">
BeyondViewController. h
//// BeyondViewController. h // 16_controller switch mode using the 1_Modal _ code method // Created by beyond on 14-7-30. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
@ Interface BeyondViewController: UIViewController // prompt who is welcome and who @ property (weak, nonatomic) IBOutlet UILabel * welcomeLabel; @ property (weak, nonatomic) IBOutlet UIButton * handle; @ property (weak, nonatomic) IBOutlet UIButton * wantLogoutBtn; // click the login button on the BeyondViewController interface to switch to BeyondLoginViewController. h. Enter the password to log on to the Account (IBAction) wantLogin :( UIButton *) sender;-(IBAction) wantLogout :( UIButton *) sender; @ end
BeyondViewController. m
//// BeyondViewController. m // 16 _ controller switch mode using the 1_Modal _ code method // Created by beyond on 14-7-30. // Copyright (c) 2014 com. beyond. all rights reserved. /* controller switching methods: 1. modal
<琢石成器—windows环境下32位汇编语言程序设计>
Chapter 5.4 dialog box) code-based switchover: storyboard-based switchover 2. push-based stack implementation managed by UINavigationController is expanded from right to left, and a new controller (on top of the stack) is displayed ), the content involved mainly includes: Custom pre-jump verification for the title of the parameter transfer navigation bar, typical example: client verification before logon jump 3. UITabbarController manages the sub-View Controller 4 in parallel, custom container, similar to the drawer effect (slide right, pop up the left sidebar) */# import "BeyondViewController. h "# import" BeyondLoginViewController. h "@ interface BeyondViewController ()
@ End @ implementation BeyondViewController-(void) viewDidLoad {[super viewDidLoad];} // click the login button on the BeyondViewController interface to switch to BeyondLoginViewController. h. Enter the password account and log on to the (IBAction) wantLogin :( UIButton *) sender {// to switch to the BeyondLoginViewController controller in Modal mode, you must create an instance object, coupling is too strong ~ BeyondLoginViewController * loginViewCtrl = [[BeyondLoginViewController alloc] init]; // set the agent of loginViewCtrl to the current controller, because after the user enters the user name and password in the next controller (loginViewCtrl, the doSomethingWithUsername method of the proxy is called to send a message to its proxy object (that is, the current controller). The parameter is the user name to pass ~ LoginViewCtrl. delegate = self; // key, code, all controllers have this method, showing [self presentViewController: loginViewCtrl animated: YES completion: ^ {NSLog (@ "BeyondLogin Controller --") ;}] ;}// implement the proxy method in the next controller, because in the next controller (loginViewCtrl, after entering the user name and password, the user will call the doSomethingWithUsername method of the proxy to send a message to its proxy object (that is, the current controller). The parameter is the user name to pass ~ -(Void) doSomethingWithLoginName :( NSString *) username {username = [NSString stringWithFormat: @ "Welcome Back: % @", username]; _ welcomeLabel. text = username; // disable the logon button _ wantLoginBtn. enabled = NO; _ wantLogoutBtn. enabled = YES;}-(IBAction) wantLogout :( UIButton *) sender {UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: @ "are you sure you want to log out? "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 whether to deregister the index as 0 if (buttonIndex = 0) {// deregister _ wantLoginBtn. enabled = YES; _ wantLogoutBtn. enabled = NO; _ welcomeLabel. text = @ "";} // The value of canceling the index is 1 doNothing} @ end.
ProtocolBeyondLoginViewControllerDelegate. h
/// BeyondLoginViewControllerDelegate. h // 16_controller switch mode modal /// Created by beyond on 14-7-30. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
@ Protocol BeyondLoginViewControllerDelegate
-(Void) doSomethingWithLoginName :( NSString *) username; @ end
BeyondLoginViewController. xib
BeyondLoginViewController. h
//// BeyondLoginViewController. h // 16_controller switch mode modal /// Created by beyond on 14-7-30. // Copyright (c) 2014 com. beyond. all rights reserved. // # import
# Import "BeyondLoginViewControllerDelegate. h "@ interface BeyondLoginViewController: UIViewController // id proxy (weak reference). Call the proxy method to pass the name entered by the user in this controller to the proxy through parameters, @ property (nonatomic, weak) id
Delegate; @ property (weak, nonatomic) IBOutlet UITextField * username; @ property (weak, nonatomic) IBOutlet UITextField * password; // submit the user name and password to the server-(IBAction) submit :( UIButton *) sender; // click the return button to return to the previous controller-(IBAction) backToHome :( UIBarButtonItem *) sender; @ end
BeyondLoginViewController. m
//// BeyondLoginViewController. m // 16_controller switch mode: descrimodal /// Created by beyond on 14-7-30. // Copyright (c) 2014 com. beyond. all rights reserved. // # import "BeyondLoginViewController. h "# import" BeyondViewController. h "# import" BeyondLoginViewControllerDelegate. h "@ interface invoke () @ end @ implementation invoke-(id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // set the password box to Asterisk _ password. secureTextEntry = YES;} // click the return button to return to the previous controller-(IBAction) backToHome :( UIBarButtonItem *) sender {// key code, close the modal mode dialog box [self dismissViewControllerAnimated: YES completion: ^ {NSLog (@ "BeyondLogin controller, disappears") ;}];} // submit the user name and password to the server-(IBAction) submit :( UIButton *) sender {// verify if (_ username. text. length = 0 | _ password. text. length = 0) {// <# (id
) #> UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: @ "Enter the username and password" delegate: nil cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "red warning" Warning: Failed: @ "other buttons", nil]; // manually display [actionSheet showInView: self. view]; // return directly;} // pass data to the previous Controller/* // method 1. The coupling is too strong and you can directly obtain the one that pops up (the previous one) controller BeyondViewController * preVC = (BeyondViewController *) self. presentingViewController; // you can set the Label of the previous controller to preVC. welcomeLabel. text = _ username. text; [self dismissViewControllerAnimated: YES completion: nil]; * // Method 2: Use a proxy to call the proxy method and use the username entered by the current controller as a parameter, the method passed to the proxy for the proxy to use [self. delegate doSomethingWithLoginName: _ username. text]; [self dismissViewControllerAnimated: YES completion: nil];} @ end