简体   繁体   中英

How to programatically change views in iOS

In Xcode 4.5 you can change views from a segue, But I want to programatically change views in Mainstoryboard. I Know in Xib. we use this method:

SecondViewController *Second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Second animated:YES];

I want to change the view when the user clicks done in the textfield (This code detects if user clicks done):

-(IBAction)hidekeyboard {

    [sender resignFirstResponder];
}

You create a segue in your storyboard that goes from the view that has the text field in question and goes to your SecondViewController . You have to assign an identifier to it (also in the storyboard, click on the line connecting the two view controllers), let's call it "segueToSecondViewController". Then, you can manually call the segue using:

[self.storyboard performSegueWithIdentifier:@"segueToSecondViewController" sender:self];

An alternative to segueing is to instantiate the viewController from the storyboard.

First you assign a Storyboard ID to the viewController in the storyboard.

在此输入图像描述

Then you instantiate that viewController, and present it.

MBTagEditorViewController *tagEditor = [self.storyboard instantiateViewControllerWithIdentifier:@"TagEditor"];
[self presentModalViewController:tagEditor animated:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM