swift - 无法从一家 VC 转到另一家,不明白为什么

标签 swift

我的应用程序中有一个注册屏幕,在用户输入电话号码并同意条款后,单击“注册”应用程序应将用户转移到下一个 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/

相关文章:

ios - NSNotification Random Like 无法识别的异常

ios - 重叠访问 "result",但修改需要独占访问;考虑复制到 Xcode 10 中的局部变量

ios - 奇怪的 Swift XCode 'Undefined Symbols' 错误

ios - swift 3.0 : Type of Expression is ambiguous without more context?

ios - 有没有办法让自定义表格 View 单元格看起来像 Xcode 6+ 中的按钮?

ios - 使用自定义单元格创建多个部分

ios - 从 iOS 10 中的本地通知启动应用程序

ios - 如何更改 TableView 标题中的 View 高度?

ios - 将数据传递给swrevealviewcontroller的每个 View Controller

ios - Swift 中 XCode 中的计算器布局困难