【发布时间】:2017-04-19 03:35:01
【问题描述】:
这里我在一个 viewController 中,我想去另一个 ID 为 ViewUSRControllerID 的 viewController 这是我的代码。用户登录后移动的目标:
@IBAction func login_btn(_ sender: UIButton) {
if username_txt.text == "" || password_txt.text == "" {
//print("empty")
let alert = UIAlertController(title: "Error", message: "you must fill up both username and password", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}else if (username_txt.text! == "admin" && password_txt.text! == "Passw0rd" ){
print("login successful")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let cr = storyboard.instantiateViewController(withIdentifier: "ViewUSRControllerID")
self.navigationController?.pushViewController(cr, animated: true)
}
}
输出是我可以打印login successful,但没有推送。为了测试,我更换了:
self.navigationController?.pushViewController(cr, animated: true)
与: self.present(cr, 动画: true)
它工作正常。但为什么推动不起作用?
【问题讨论】:
-
您的控制器是否嵌入了导航控制器?
-
我认为是,请再次参考问题。我已经更新了。
-
我的错,我明白了;)
-
您要从哪个控制器推送?
标签: ios swift3 uinavigationcontroller pushviewcontroller