【发布时间】:2018-05-18 14:31:43
【问题描述】:
单击按钮时如何更改视图控制器。我没有使用情节提要。这些视图都是以编程方式创建的。
我尝试将目标添加到按钮,然后调用以下方法来推送新的视图控制器:
func switchView() {
print(123)
let prodListController = ProductListController()
self.navigationController?.pushViewController(prodListController, animated: true)
}
这是从 UIviewController 类中调用的。
任何帮助将不胜感激。谢谢!!
编辑: 做了以下修改:
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: ProductListController())
【问题讨论】:
-
如果这段代码没有做任何事情,那么我认为你的
navigationController可能是nil。
标签: ios swift swift3 uiviewcontroller uibutton