IBOutlet 为 nil,但在 storyboard 中连接,Swift [英] IBOutlet is nil, but it is connected in storyboard, Swift

查看:49
本文介绍了IBOutlet 为 nil,但在 storyboard 中连接,Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Swift 1.1 和 Xcode 6.2.

Using Swift 1.1 and Xcode 6.2.

我有一个 UIStoryboard,其中包含一个单一的自定义 UIViewController 子类.在它上面,我有一个 @IBOutlet 类型的 UIView 连接,从那个控制器到故事板上的 UIView subclass.对于该视图的子视图,我也有类似的出口.见图A.

I have a UIStoryboard containing a singular, custom UIViewController subclass. On it, I have an @IBOutlet connection of type UIView from that controller to a UIView subclass on the storyboard. I also have similar outlets for subviews of that view. See figure A.

但在运行时,这些属性为零(图B).即使我已经保证我已经连接了 Interface Builder 中的插座.

But at run time, these properties are nil (Figure B). Even though I have assured I've connected the outlets in Interface Builder.

想法:

  • 是否有可能因为我使用子类的子类而导致初始化混乱?我没有覆盖任何初始化程序
  • awakeFromNib: 由于某种原因没有被调用
  • 也许它没有连接到子视图上的子视图
  • Is it possible that because I am using a subclass of a subclass something messes up with the initialization? I am not overriding any initializers
  • awakeFromNib: is not getting called for some reason
  • Maybe it doesn't connecting to subviews on subviews

我尝试过的事情:

  • 完全匹配 @IBOutlet 和故事板项目类型(而不是 UIView)
  • 删除属性和插座并重新添加它们
  • Matching @IBOutlet and storyboard item types exactly (instead of UIView)
  • Deleting property and outlet and re-added them

图A*

图B

*图A中被遮挡的代码是:

@IBOutlet private var annotationOptionsView: UIView!
@IBOutlet private var arrivingLeavingSwitch: UISegmentedControl!

谢谢.

推荐答案

故事板无法识别我添加到其中的任何其他 UI 内容.在运行时,所有引用都为零.所以我清除了我的派生数据文件夹,然后这些连接再次工作.

The storyboard wasn't recognizing any further UI things I added to it. At run time all the references were nil. So I cleared my derived data folder and then those connections worked again.

这篇关于IBOutlet 为 nil,但在 storyboard 中连接,Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆