从另一个 ViewController 呈现故事板 ViewController [英] Present storyboard ViewController from another ViewController
问题描述
我的 iOS 应用的故事板中有多个 UIViewController.我想从不同的 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 Storyboards 执行此操作?
How can I perform this action with iOS 5 Storyboards?
推荐答案
假设你有 storyboard,去 storyboard 并给你的 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 呈现故事板 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!