备忘:
今天 Swift项目中遇到一个问题,一个使用 xib 创建的 vc,在 iOS9 中是正常跳转的,但是 iOS8 crash
OC 中使用 [[MyVC alloc] init]
会自动加载一个同名的 xib 文件
Swift 中使用 MyVC()
初始化时,在 iOS9 及以上 可以自动加载,但是 iOS8 中不会自动加载同名 xib
此时需 public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)
/*
The designated initializer. If you subclass UIViewController, you must call the super implementation of this
method, even if you aren't using a NIB. (As a convenience, the default init method will do this for you,
and specify nil for both of this methods arguments.) In the specified NIB, the File's Owner proxy should
have its class set to your view controller subclass, with the view outlet connected to the main view. If you
invoke this method with a nil nib name, then this class' -loadView method will attempt to load a NIB whose
name is the same as your view controller's class. If no such NIB in fact exists then you must either call
-setView: before -view is invoked, or override the -loadView method to set up your views programatically.
*/
public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)
网友评论