在这里,我在一个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,动画:真)
在它工作正常。但为什么推动不起作用?
是你的控制器内嵌有导航控制器? –
我认为这是,请再次参考问题。我已经更新了它。 –
我的不好,我已经得到了;) –