ios - 如何使用 PresentViewController 在 Storyboard中引用 ViewController

标签 ios objective-c xcode

我在 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/

相关文章:

ios - 有附加内容时 ScrollView 顶部/底部的渐变

ios - 在 iOS 8.3 上使用 CoreSpotlight (9.0+) 启动应用程序时 Xcode 崩溃

iphone - 如何在iPhone SDK中实现UIProgressView

iphone - App Store 提交错误 : A symbolic link resolves to a location outside of the binary

iphone - 在 Interface Builder 中使用自定义字体定位 UILabel

用于白标应用程序的 iOS 静态库代码库

xcode - 在xcode中包含boost

iphone - 如何使用 CoreGraphics 用 alpha 颜色填充矩形?

ios - UIView包含标签iOS如何改变标签的颜色

iphone - 到达 sender 对象的 'tag' 属性