从另一个ViewController呈现storyboard ViewController [英] Present storyboard ViewController from another ViewController
问题描述
我在iOS App的Storyboard中有多个UIViewControllers。我想从一个不同的UIViewController打开一个UIViewControllers(在故事板中)。
I have multiple UIViewControllers in my iOS App's Storyboard. I want to open one of the UIViewControllers (in the storyboard) from a different UIViewController.
我已经尝试了下面的代码,但即使我没有工作在iOS 5之前使用它并且它工作正常。
I've tried the code below, but it isn't working even though I used it before iOS 5 and it worked fine.
- (IBAction)addNotes:(id)sender {
NotesViewController *notesView = [[NotesViewController alloc] initWithNibName:@"NotesViewController" bundle:nil];
[self presentModalViewController:notesView animated:YES];
}
如何在iOS 5故事板中执行此操作?
How can I perform this action with iOS 5 Storyboards?
推荐答案
假设您有故事板,请转到故事板并给VC一个标识符(检查员),然后执行:
Assuming you have storyboard, go to storyboard and give your VC an identifier (inspector), then do:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"];
[self.navigationController pushViewController:vc animated:YES];
假设你想要一个xib文件:
Assuming you have a xib file you want to do:
UIViewController *vc = [[UIViewController alloc] initWithNibName:@"NIBNAME" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
没有xib文件:
UIViewController *vc = [[UIViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
这篇关于从另一个ViewController呈现storyboard ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!