我在 UITabBarViewController 中有四个选项卡。每个 View 都将 UIButtons 添加到它们的导航栏,并且每个选项卡都有一个“发布按钮”,可将用户带到发布页面。
如何引用已经存在于 Storyboard中的 ViewController,以便我可以将其传递到 PresentViewController:
方法中?
例如,这是从四个标签栏 View 中的任何一个单击发布按钮时使用的方法:
- (void)postInvoked:(UIBarButtonItem *)sender
{
[self presentViewController:______ animated:YES completion:nil];
}
空白处是什么?我想我需要避免像这样引用 UIViewController:
UIViewController * postPage = [[UIViewController alloc] init];
因为这会在用户每次导航到页面时创建一个新的页面实例。
最佳答案
您必须创建要呈现的 Controller 实例:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
UIViewController *controller = [mainStoryboard instantiateViewControllerWithIdentifier: @"<Controller ID>"];
这将使用 Storyboard中的预配置 View 创建 Controller 。
@Interface Builder 中的“Controller ID”==“Storyboard ID”属性。 (选择 Controller 时的检查器选项卡)
随心所欲地呈现。
[self presentViewController:controller animated:YES completion:nil];
关于ios - 如何使用 PresentViewController 在 Storyboard中引用 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22749261/