Modal view (iOS development)

Source: Internet
Author: User

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)

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.