Swift:从xib编程创建UIViewController
Swift:从xib编程创建UIViewController
这些天我正在学习Swift,我有一个问题。
如果我想要以编程方式创建一个新的UIViewController该怎么办呢?
对于一个空/新的视图控制器很容易:
var controller: UIViewController = UIViewController() controller.view.backgroundColor = UIColor.whiteColor() self.presentViewController(controller, animated: true, completion: nil)
但是,我有一个xib文件,我想要在控制器上加载它:
var controller: UIViewController = UIViewController(nibName: "FeedDetail", bundle: nil) controller.view.backgroundColor = UIColor.whiteColor() self.presentViewController(controller, animated: true, completion: nil)
这个会导致程序崩溃,因为:
'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "FeedDetail" nib but the view outlet was not set.'
我已经阅读了这篇帖子,但我不明白问题出在哪里!
admin 更改状态以发布 2023年5月23日