我的应用程序中有一个注册屏幕,在用户输入电话号码并同意条款后,单击“注册”应用程序应将用户转移到下一个 vc。问题是,虽然一切看起来都很好,但应用程序不会移动到下一个屏幕。 这是我的代码:
func handleRegister() {
if UserDefaults.standard.object(forKey: USER_AGREED) == nil {
let alert = UIAlertController(title: "Terms and Conditions", message: "Please agree to the terms and conditions to continue", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (alert) in
self.showTermsAndConditions()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .destructive, handler: nil))
self.present(alert, animated: true)
}else{
guard let userPhoneNumber = self.mView.textField.text else { return }
UserDefaults.standard.set(userPhoneNumber, forKey: USER_PHONE_NUMBER)
let vc = Tabbar()
self.navigationController?.pushViewController(vc, animated: true)
}
}
我试图放置一个断点,它确实在应该到达 else block 时到达了 else block ,并识别了 Tabbar,但就是不会移动到那里。 有什么建议吗?
最佳答案
这里有两个可能的麻烦源。
你是说
self.navigationController?
。问号的意思是:“如果我没有navigationController
,什么都不做。”如果你没有navigationController
,你什么都不做。也许你的意思是self.present(vc, animated:true)
。你说的是
let vc = Tabbar()
。那不是界面或 Storyboard 中的现有 View Controller 。所以当你移动到那里时,它可能是空的(这取决于 Tabbar View Controller 的构造方式)。
关于swift - 无法从一家 VC 转到另一家,不明白为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56819546/