swift项目在iOS8 通过init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle
2017-07-06 16:46
567 查看
初始化代码:
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也是可以解决的。
相关文章推荐
- Q10:fatal error:use of unimplemented initializer init(nibName nibNameOrNil: String?, bundle nibBundl
- [[MyViewController alloc] initWithNibName:nil bundle:nil]; 搜索 Nib 文件的规则及注意事项
- ios view的几种加载函数的区别didFinishLaunchingWithOptions、initWithNibName:bundle、loadView、viewWillAppear
- initWithNibName 和 [[NSBundle mainBundle] loadNibNamed] 的区别
- initWithNibName:bundle awakeFromNib 区别
- 总结Nib(xIB)、File's owner、NSBundle、loadView/viewDidLoad、initWithNibName的相关基础知识
- iOS Development: Proper Use of initWithNibName:bundle: Affects UITableViewController
- [[ViewController alloc]init]与[ViewController alloc]initWithNibName: bundle: ]的区别;
- [NSURL initFileURLWithPath:]: nil string parameter 错误的解决方案
- loadView和viewDidLoad及initWithNibName/awakeFromNib/initWithCoder
- initWithNibName导致的初始化问题
- initWithNibName与viewDidLoad的执行关系以及顺序
- loadView/viewDidLoad/initWithNibName/awakeFromNib/initWithCoder的用法
- initWithNibName/awakeFromNib/initWithCoder
- iphone+ios+loadView/viewDidLoad/initWithNibName/awakeFromNib/initWithCoder/initWithFrame
- initWithNibName的初始化问题
- Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.init
- initWithNibName
- initWithNibName导致的初始化问题
- initWithNibName的初始化问题