![](/img/trans.png)
[英]ViewController from StoryBoard make ViewDidLoad called twice
[英]How to make ViewController load itself from nib on viewDidLoad() properly?
所以我有一个我的CustomViewController的nib文件,每次我想呈现这个控制器我都这样做
let vc = CustomViewController(nibName: "CustomViewController", bundle: nil)
self.present(vc, animated: true, completion: nil)
我想要的是让CustomViewController自己从nib加载自己。 因此,父VC中的调用将是这样的
let vc = CustomViewController()
self.present(vc, animated: true, completion: nil)
在CustomViewController中添加此init方法。 它将根据您的需要工作。
convenience init() {
self.init(nibName: "CustomViewController", bundle: nil)
}
试试这种方式....
MyViewClass *myViewObject = [[[NSBundle mainBundle] loadNibNamed:@"MyViewClassNib" owner:self options:nil] objectAtIndex:0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.