iOS 8.4 - iboutlet没有在编程创建的视图控制器中填充 [英] iOS 8.4 - iboutlet not populating in programmatically created view controllers
问题描述
在iOS 8.4中以编程方式加载UIViewController时,我一直看到IBOutlets注册为nil。这导致任何iOS 8.4设备崩溃。完全相同的代码在iOS 9和9.0.1上顺利运行。作为参考,这是视图控制器的片段
When loading a UIViewController programmatically in iOS 8.4 I am consistently seeing the IBOutlets registering as nil. This is causing crashes on any iOS 8.4 device. The exact same code runs smoothly on iOS 9 and 9.0.1. For reference, this is a snippet of the view controller
class B8AVPermissionsViewController: B8BaseViewController {
@IBOutlet weak var closeButton: UIButton!
@IBOutlet weak var cameraButton: UIButton!
@IBOutlet weak var microphoneButton: UIButton!
var delegate: B8PermissionRequestingDelegate? = nil;
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated);
NSLog("cameraButton: \(cameraButton)")
}
打印出 cameraButton:nil
创建它的代码如下所示:
The code that creates this looks like:
self.permissionViewController = B8AVPermissionsViewController()
self.permissionViewController!.delegate = self
dispatch_async(dispatch_get_main_queue(), {
self.presentViewController(self.permissionViewController!, animated: true, completion: nil)
})
我做错了什么?
推荐答案
问题是iOS 8中存在错误。说 iOS 8中的B8AVPermissionsViewController()
不会自动加载关联的笔尖。你需要解决这个问题;例如,您可以显式调用 init(nibName:bundle :)
,然后告诉它是nib所在的位置。
The problem is that there's bug in iOS 8. Saying B8AVPermissionsViewController()
in iOS 8 does not automatically load the associated nib. You need to work around this; for example, you could call init(nibName:bundle:)
explicitly and tell it where the nib is.
该错误已在iOS 9中修复,这就是为什么你没有看到同样的问题。
The bug is fixed in iOS 9, which is why you're not seeing the same problem there.
这篇关于iOS 8.4 - iboutlet没有在编程创建的视图控制器中填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!