[英]How to programatically change views in iOS
在Xcode 4.5中,您可以从segue更改视图,但我想以编程方式更改Mainstoryboard中的视图。 我知道在Xib。 我们使用这种方法:
SecondViewController *Second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Second animated:YES];
我想在用户在文本字段中单击完成时更改视图(此代码检测用户是否单击完成):
-(IBAction)hidekeyboard {
[sender resignFirstResponder];
}
您在故事板中创建了一个segue,它来自具有相关文本字段的视图,并转到SecondViewController
。 你必须为它分配一个标识符(也在故事板中,单击连接两个视图控制器的线),让我们称之为“segueToSecondViewController”。 然后,您可以使用以下方法手动调用segue:
[self.storyboard performSegueWithIdentifier:@"segueToSecondViewController" sender:self];
segueing的替代方法是从故事板中实例化viewController。
首先,将Storyboard ID分配给storyboard中的viewController。
然后,您实例化该viewController,并呈现它。
MBTagEditorViewController *tagEditor = [self.storyboard instantiateViewControllerWithIdentifier:@"TagEditor"];
[self presentModalViewController:tagEditor animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.