初始化代码:
MatchViewControllerPhone(nibName:"MatchViewControllerPhone", bundle: nil)
MatchViewControllerPhone类部分代码:
class MatchViewControllerPhone: UIViewController
@IBOutlet weak var container: UIScrollView!
// MARK: - Life cycle
override func viewDidLoad() {
super.viewDidLoad()
self.container.delegate = self //在iOS8设备上报错:fatal error: unexpectedly found nil while unwrapping an Optional value
}
}
查看发现xib里的子控件都为nil导致的。
后来发现init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)中nibNameOrNil参数在iOS8中为空,所有有以下解决方案:
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
let classString = String(describing: type(of: self))
super.init(nibName: nibNameOrNil ?? classString, bundle: nibBundleOrNil)
}
ps:
1、在iOS9iOS10设备上是好的,估计被苹果修复了
2、在storyboard中也是好的,所以xib换成storyboard也是可以解决的。
相关推荐
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) // Custom initialization } override func viewDidLoad() { super.viewDidLoad() self.drawerState = ICSDrawerControllerState....
斯威夫特 在Swift项目中获取强大的类型化,自动完成的资源,例如图像,字体和序列为什么要使用这个? 它使您的代码使用资源: 全类型输入,更少的转换和猜测方法将返回什么检查了编译时间,没有更多不正确的字符串...
在Xcode7 SWIFT项目中打开。 另外,您需要将QuartzCore-Framework添加到您的项目中。 ##用法 首先,您必须导入类别 只需使用presentPopupViewController:animationType,fe: 让myPopupViewController:...
请随时关注最新更新:要求iOS 10.0 Xcode 9 迅捷4.0安装您可以通过几种方式安装garland-view : 将源文件添加到您的项目。 使用 : pod 'garland-view' 使用: github "Ramotion/garland-view"用法花环景观Garland...
有点像一个状态机,用于在 iOS 上浏览不同的视图控制器。 有时,您有一组 ViewController,它们通过您的应用程序在各种工作流程中重复使用。 你真的不应该在你的 ViewControllers 中存储所有这些状态,因为这会变得...
CustomizableActionSheet 操作表允许包含您的自定义视图和按钮。 安装 ...if let sampleView = UINib ( nibName : " SampleView " , bundle : nil ). instantiateWithOwner ( self , options : nil
定制CollectionView的示例: 自定义页脚/页眉用NibName初始化 [self.collectionView registerNib:[UINib nibWithNibName:@"HeaderCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:...