切换到 Xcode 6 Beta 5 后,所有 IBOutlets 都变为 nil [英] All IBOutlets become nil after switching to Xcode 6 Beta 5

查看:22
本文介绍了切换到 Xcode 6 Beta 5 后,所有 IBOutlets 都变为 nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,视图控制器中有一个属性

For instance, there is a property in a view controller

@IBOutlet weak var nameLabel: UILabel!

此属性在 viewWillAppearviewDidLoad 中为 nil,因此应用程序在运行时崩溃.

This property is nil inside viewWillAppear and viewDidLoad, so the app crashes at runtime.

它在 Xcode 6 Beta 4 中运行良好.在我切换到 Beta 5 后,它抱怨控制器类 没有实现其超类的必需成员.所以我加了

It was working fine in Xcode 6 Beta 4. After I switched to Beta 5, it complained about the controller class does not implement its superclass's required members. So I added

required init(coder aDecoder: NSCoder!) {
  super.init(coder: aDecoder)
}

那个编译器错误消失了.但是,应用程序崩溃时 unexpectedly found nil while unwrapped an Optional value 因为当我尝试设置它的 nameLabel 属性是 nil文字.

And that compiler error disappeared. However, the app crashes for unexpectedly found nil while unwrapping an Optional value because that nameLabel property is nil when I try to set its text.

我通读了发行说明,但不知道如何解决这个问题.

I read through the release notes and could not figure out how to fix this issue.

推荐答案

我在 Beta5 中遇到了同样的问题.这似乎是一个问题

I was having the same issue in Beta5. It appears to be a problem where

init(nibName: nil, bundle: nil) 

没有将 nil 映射到默认的 nibName.当我更改为显式 nibName 时,它​​起作用了.特别是在我的情况下,使用新的 ??操作员:

is not mapping nil to the default nibName. When I changed to an explicit nibName then it worked. Specifically in my case, using the new ?? operator:

override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
   // beta5 workaround: replace nil with explicit name of xib file
   let nib = nibNameOrNil ?? "MyViewController"

   super.init(nibName: nib, bundle: nibBundleOrNil)

   // local initialization here
}

让它再次神奇地工作.

这篇关于切换到 Xcode 6 Beta 5 后,所有 IBOutlets 都变为 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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