在 ViewDidLoad return 中使用笔尖创建 ViewController 无
Create ViewController using nib in ViewDidLoad return nil
我有一个 Container ViewController A 和一个 Child ViewController B
在 ViewController A 的 viewDidLoad 中,我从笔尖初始化 ViewControler B 并将其添加为 Viewcontroller A 的子级,但 ViewControler B 始终为零。
这是我的代码。
override func viewDidLoad() {
self.currentViewController =
ViewControlerB(nibName: "ViewControllerB", bundle: nil)
self.currentViewController!.view
.translatesAutoresizingMaskIntoConstraints = false
self.addChildViewController(self.currentViewController!)
self.addSubView(self.currentViewController!.view,
toParentView: viewContainer)
super.viewDidLoad()
}
我的 self.currentViewController 始终为零并导致崩溃。谁能给我解释一下这是为什么?
请帮忙^^'
我希望你检查这两个答案:
1- 检查笔尖名称。
2- 将 bundle 从 nil 更改为 (NSBundle.mainBundle()).
我有一个 Container ViewController A 和一个 Child ViewController B 在 ViewController A 的 viewDidLoad 中,我从笔尖初始化 ViewControler B 并将其添加为 Viewcontroller A 的子级,但 ViewControler B 始终为零。
这是我的代码。
override func viewDidLoad() {
self.currentViewController =
ViewControlerB(nibName: "ViewControllerB", bundle: nil)
self.currentViewController!.view
.translatesAutoresizingMaskIntoConstraints = false
self.addChildViewController(self.currentViewController!)
self.addSubView(self.currentViewController!.view,
toParentView: viewContainer)
super.viewDidLoad()
}
我的 self.currentViewController 始终为零并导致崩溃。谁能给我解释一下这是为什么?
请帮忙^^'
我希望你检查这两个答案:
1- 检查笔尖名称。
2- 将 bundle 从 nil 更改为 (NSBundle.mainBundle()).