我希望能够通过编程创建一个UIViewController
,而不使用nib或storyboard。
我认为只需将UIViewController
实现为以下形式:
class TestViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//Add some setup code here, without it it should just be blank
}
}
使用 let vc = TestViewController(nibName: nil, bundle: nil)
或者 TestViewController()
实例化,然后将其推入到导航栈中即可:
navigationController?.pushViewController(vc, animated: true)
但它显示了带有透明视图的navigationController
(上方栏)(我有一个多窗口设置,背后显示了UIWindow
)。
viewDidLoad
而不是loadView
。这就是我的问题所在。 - DanielloadView
方法。 - Ahmed Onawale