Modal view (IOS development), modal view ios development

Source: Internet
Author: User

Modal view (IOS development), modal view ios development

Mode: the mode view slides out from the bottom of the screen. When you complete the operation, you need to disable the mode view. If you do not disable the mode view, you cannot do anything else. It must have the meaning of Response Processing.

Main View Controller --- modal View Controller. The parent-child relationship exists between the Controller and the Controller.

In the UIViewController class, there are two main methods:

PresentViewController: animated: completion presents the modal View

DismissViewControllerAnimated: completion disable the 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, the delegated design mode or broadcast notification mechanism should be used // here is the broadcast notification mechanism // register a custom notification RegisterCompletionNotification. When the notification arrives, the registerCompletion: message is sent, the parameter notification can contain the callback parameters, which are stored in the NSDictionary dictionary [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (registerCompletion :) name: @ "RegisterCompletionNotification" object: nil];}-(void) registerCompletion :( NSNotification *) notification {// get the parameter userInfo, which is a dictionary NSDictionary * theData = [notification userInfo]; // obtain the dictionary's username index value NSString * username = [theData objectForKey: @ "username"]; NSLog (@ "username = % @", username);}-(void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .} -(IBAction) regonclick :( id) sender {// use the ID of registerViewController to obtain the View Controller object UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName: @ "Main" bundle: nil]; UIViewController * registerViewController = [mainStoryboard instantiateViewControllerWithIdentifier: @ "registerViewController"]; // sets the animation effect when the modal view is rendered and disabled. // exit registerViewController from the bottom up in the vertical direction. modalPresentationStyle = UIModalTransitionStyleCoverVertical; // call the completion code block when the rendering is complete. // The code block will be called later. [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 didreceivemorywarning]; // Dispose of any resources that can be recreated .} /* # pragma mark-Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation-(void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller .} */-(IBAction) done :( id) sender {// close the modal view, and then continue to call the code block [self dismissViewControllerAnimated: YES completion: ^ {// code block NSLog (@ "Modal View done"); // create a dictionary object named NSDictionary * dataDict = [NSDictionary dictionaryWithObject: self.txt username. text forKey: @ "username"]; [[nsnotifcenter center defacenter center] postNotificationName: @ "RegisterCompletionNotification" object: nil userInfo: dataDict] ;}@ end



IOS development video tutorial UI: 37. What are the modes view and control direction mov seeds? Thank you

IOS development video tutorial UI: 3.7 modal view, control direction. mov seed:
Thunder: // QUFodHRwOi8vYWlrYW5keS5vcmcvaU9T5byA5Y + Platform + WItuaWueWQkS5tb3Y/Platform
Despise and take the seeds to drop people !!!

Ios development: How to click a button to jump to a new interface ,~~~

1. You can use the navigation controller stack. Use the current view controller as the rootViewController. You need to create it in the code that creates the current controller.
UIViewController * vc1 = [[UIViewControlelr alloc] init];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController: vc1];
[Vc1 release];
[Window addSubView: navController. view];
[NavController release];

PushViewController can be used to navigate other views only when the current controller is in the navigation controller stack.
Navigate to the New View Controller:
UIViewController * vc2 = [[ViewController alloc] init];
[Self. navigationController pushViewController: vc2 animated: YES];
[Vc2 release];
2. Modal View
UIViewController * vc2 = [[ViewController alloc] init];

[Self presentModalViewController: controller animated: YES];
[Vc2 release];

3. overwrite the current view with the new view
If this method is used, we recommend that you create a controller swithController that can maintain the interaction between controllers. In this controller, You can implement view switching between different controllers.
@ Inertface SwitchViewController: UIViewController
@ Property (retain) UIViewController * vc1
@ Property (retain) UIViewController * vc2;

-(Void) showVC1;
-(Void) showVC2;
@ End

@ Implementation SwitchViewController
@ Synthesize vc1, vc2;

-(Void) showVC1 {
If (vc2 ){
[Vc2.view removeFromSuperView];
}

[Self. view addSubView: vc1.view];
}
@ End
 

Related Article

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.