ios - 无法将 UIViewController IBOutlets 与 StoryBoard 链接

标签 ios xcode uiviewcontroller storyboard iboutlet

Storyboard中有两个 UIViewController(A 和 B)。 A View Controller 有一个属性

@property (nonatomic, retain) IBOutlet UIViewController *viewController;

我想通过 Storyboard链接到 B。

socket 显示在 Storyboard菜单中的 IBOutlets 部分下,但我无法链接。 为什么我要这样做似乎很奇怪,但我需要它。有人知道怎么做吗?

最佳答案

IBOutlets 是单个 View Controller 中的连接。在 View Controller 中创建对对象的引用,以便您可以在代码中使用这些对象。

您不能从一个 View Controller 创建 IBOutlets 到另一个 View Controller 。属性是正确的方法,但您必须在代码中分配属性。通常,当一个 View Controller 创建另一个 View Controller 时,它可能会设置对自身的引用。

OtherViewController *otherViewController = [OtherViewController alloc] init];
otherViewController.masterViewController = self;
// at this point "otherViewController" has a reference to the current view controller

关于ios - 无法将 UIViewController IBOutlets 与 StoryBoard 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14217182/

相关文章:

ios - 如何将 Youtube 视频嵌入到我的应用程序中?

ios - 适用于 iOS 7.1 的 SKShapeNode 和 swift

ios - 更新SQLite数据库时,应用程序崩溃并显示断言失败消息

iphone - 编写父 View Controller 的终极指南

ios - 无法将两个 AlertController 放在同一个 VC 上

ios - 强制关闭应用程序后位置更新是否继续运行

ios - Xcode "Missing Submodule"警告

objective-c - 自定义 NSButton 焦点环颜色

objective-c - 了解 gcov 文件中的分支

ios - 在 View Controller 之间传递数据