在這裏,我在一個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,動畫:真)
在它工作正常。但爲什麼推動不起作用?
是你的控制器內嵌有導航控制器? –
我認爲這是,請再次參考問題。我已經更新了它。 –
我的不好,我已經得到了;) –