ios - 为什么我的代码没有进入下一个 View

标签 ios swift

调试时没有错误。接受登录后,代码不会进入下一页...请帮助

if (emailValue == userEmail || passValue == userPassword) {

    //store user information in the app to maintain session

    let defaults = UserDefaults.standard

    defaults.set(usernameValue, forKey: "usernameValue")
    defaults.set(nameValue, forKey: "nameValue")
    defaults.set(emailValue, forKey: "emailValue")

    // Display Alert Message with confirmation
    let myAlert = UIAlertController(title: "Success!", message: Constants.SucessMessages.EIRP, preferredStyle: UIAlertControllerStyle.alert);
    let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default){ action in
        self.dismiss(animated: true, completion: nil);
        if let navController = self.navigationController {
            navController.popViewController(animated: true)
        }
    }
    myAlert.addAction(okAction);
    OperationQueue.main.addOperation {
        self.present(myAlert, animated: true, completion: nil)
    }

}

最佳答案

您想转到下一个屏幕,但您使用的代码是用于点击 okAction 转到上一个屏幕

假设目标 Controller 的名称是 DestinationViewController,使用的 ID 是 DestinationVCID,根据您当前的使用情况,可以使用以下选项转到下一个屏幕。

代码必须用于您使用的 UIAlertAction,即 okAction

推送

if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DestinationVCID") as? DestinationViewController {

        if let navigator = navigationController {
            navigator.pushViewController(viewController, animated: true)
        }
}

现在

if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DestinationVCID") as? DestinationViewController
{
     present(vc, animated: true, completion: nil)
}

关于ios - 为什么我的代码没有进入下一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45736641/

相关文章:

ios - 适用于 3.5 和 4 英寸屏幕的应用程序底部的 iAd 横幅

ios - 将带有分页的 UIScrollView 添加到现有的 UIViewController

ios - 所有 View Controller 的多维数组

timer - Swift:测试 NSTimer 的过期/失效似乎失败

ios - 为当前用户调用 Parse Cloud Function

ios - 2 具有不同自定义单元格的 UITableView

iOS 为什么我的 UIPickerview 方法循环?

json - 如何根据 'type' 为多个结构手动实现 Codable?

objective-c - 自定义 UITextField 清除按钮

ios - 根据设备大小缩放多行 UIButton 上的字体