Ios controller modal Learning

Source: Internet
Author: User

Code creation:

1. appdelegate puts contoller under the controller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];        self.window.rootViewController = [[MJOneViewController alloc] init];        [self.window makeKeyAndVisible];    return YES;}
2. Actions redirected to oneViewController

Get the controller to jump to, and then use the current controller to call presentViewController

-(IBAction) jump {// display MJTwoViewController * two = [[MJTwoViewController alloc] init]; UINavigationController * nav = [[UINavigationController alloc] callback: two]; [self presentViewController: nav animated: YES completion: ^ {NSLog (@ "indicates that MJTwoViewController has been completed ....... ") ;}] ;}
3. twoController returns the previous controller

Call the dismissViewController Method

-(IBAction) cancel {// NSLog (@ "% @", self. view. window. rootViewController); // NSLog (@ "% @", self. view. window. subviews); [self dismissViewControllerAnimated: YES completion: ^ {NSLog (@ "Disable MJTwoViewController .... ") ;}]; // [self. navigationController dismissViewControllerAnimated: YES completion: ^ {// NSLog (@ "Disable MJTwoViewController .... "); //}];}


It is also convenient to create a modal controller on the storyBoard. Press ctrl and right-click to select moadal mode.




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.