我正在使用ForgotPassword按钮,这没问题,如果单击它,它将调用performSegueWithIdentifier并打开一个新的ViewController。现在,如果凭据错误(密码错误),我将收到登录警报,并添加了一个按钮来请求密码以调用ForgotPassword。

问题是它调用AlertAction是正确的,这调用了forgotPassword IBAction,并且performSegue也被正确调用了,但是视图不会出现。

// MARK: Actions
private func forgotPasswordAlertAction(action: UIAlertAction) {
    print("AlertRequestAction")
    forgotPassword(action)
}

@IBAction func forgotPassword(sender: AnyObject) {
    print("forgotPasswortAction")
    print(self)
    performSegueWithIdentifier(forgotPasswordId, sender: self)
}


// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == forgotPasswordId,
        let controller = segue.destinationViewController as? AccountForgotPasswordViewController {
        print("forgotPasswortSegue")
        controller.emailFromInput = emailTextField.text
    }
}


ios - 快速警报操作不适用于segue-LMLPHP

private func showError(error: AuthenticationError) {
    let title = NSLocalizedString("Error", comment: "Generic Title if an unkown error occured.")
    let message = NSLocalizedString("An Error occured. Please try again.", comment: "Generic Message if an unkown error occured.")

    let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
    let dismissAction = UIAlertAction(title: NSLocalizedString("OK", comment: "Generic OK Button label"), style: .Default, handler: nil)

    switch error {
    case .BadCredentials:
        alertController.title = NSLocalizedString("Invalid Credentials", comment: "Title if provided credentials are invalid.")
        alertController.message = NSLocalizedString(
            "The entered credentials are invalid. Please try again with valid credentials or request a new password.",
            comment: "Generic Title if an unkown error occured.")


        let forgotPasswordAction = UIAlertAction(
            title: NSLocalizedString("Request Password", comment: "Request Password Button Label"), style: .Default, handler: forgotPasswordAlertAction)
        alertController.addAction(forgotPasswordAction)
    default:
        break
    }

    alertController.addAction(dismissAction)
    alertController.preferredAction = dismissAction
    presentViewController(alertController, animated: true, completion: nil)
}

最佳答案

在您的情况下,我能想象的唯一问题-当您被称为警报时,您以某种方式从主队列中移出了。通过在print(NSThread.isMainThread()函数中添加行forgotPasswordAlertAction(_:)来确认这一点。并且如果您将在控制台中看到false,请分派到主队列:

private func forgotPasswordAlertAction(action: UIAlertAction) {
    print("AlertRequestAction")
    print(NSThread.isMainThread())

    dispatch_async(dispatch_get_main_queue()) {
        self.forgotPassword(action)
    }
}

关于ios - 快速警报操作不适用于segue,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37613174/

10-09 13:04