Modal: Modal view slides out from the bottom of the screen and needs to close the modal view when it is finished, and if it does not close, it cannot do anything else and must have the meaning of response processing.
The main view controller----modal views controller. The primary view controller is a parent-child relationship between the modal views controller.
In the Uiviewcontroller class, there are two main methods:
PresentViewController:animated:completion Rendering modal views
Dismissviewcontrolleranimated:completion Close Modal View
Code:
ViewController.h
#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller-(ibaction) Regonclick: (ID) sender; @end
Viewcontroller.m
#import "ViewController.h" #import "RegisterViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; If you want to pass parameters, you should use the delegate design mode or broadcast notification mechanism//here for the broadcast notification mechanism//register a custom notification registercompletionnotification, notify the arrival time issued Registercompletion: message, its parameter notification can contain callback parameters, unified in the Nsdictionary dictionary [[nsnotificationcenter defaultcenter] addobserver:self selector:@ Selector (registercompletion:) name:@ "Registercompletionnotification" object:nil]; }-(void) Registercompletion: (nsnotification *) notification{//Get parameter userinfo, is a dictionary nsdictionary *thedata = [Notificat Ion UserInfo]; Gets the username index value of the dictionary nsstring *username = [thedata objectforkey:@ "username"]; NSLog (@ "username =%@", username);} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} -(Ibaction) Regonclick: (ID) Sender {//Use Registerviewcontroller ID to get View Controller object Uistoryboard *mainstoryboard = [UistorYboard storyboardwithname:@ "Main" bundle:nil]; Uiviewcontroller *registerviewcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@] Registerviewcontroller "]; Animate when modal view is rendered and closed//vertical exit from bottom up Registerviewcontroller.modalpresentationstyle = Uimodaltransitionstylecoververti Cal Call completion code block//code block when rendering complete [self Presentviewcontroller:registerviewcontroller animated:yes completion:^{ NSLog (@ "Present Modal View"); }];} @end
ResgisterViewController.h
#import <UIKit/UIKit.h> @interface registerviewcontroller:uiviewcontroller-(ibaction) Done: (ID) sender;@ Property (weak, nonatomic) Iboutlet Uitextfield *txtusername; @end
Resgisterviewcontroller.m
#import "RegisterViewController.h" @interface Registerviewcontroller () @end @implementation registerviewcontroller-( void) Viewdidload {[Super viewdidload]; Do any additional setup after loading the view.} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} /* #pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before Nav igation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [SEG UE Destinationviewcontroller]. Pass the selected object to the new view Controller.} */-(ibaction) Done: (ID) Sender {//close modal view, then continue calling code block [self dismissviewcontrolleranimated:yes completion:^{// Code block NSLog (@ "Modal View done"); Create a Dictionary object indexed by username nsdictionary *datadict = [Nsdictionary dictionaryWithObject:self.txtUsername.text forkey:@ "Username"]; [[NsnotificatIoncenter Defaultcenter] postnotificationname:@ "registercompletionnotification" Object:nil userInfo:dataDict]; }]; } @end
Modal view (iOS development)