ios - 单击警报按钮不起作用时更改 View

标签 ios swift xcode firebase firebase-authentication

你好,

这是我的代码:

@IBAction func logOutAction(sender: AnyObject) {

        try! FIRAuth.auth()!.signOut()
    let alertController = UIAlertController(title: "Sure?", message: "Are you sure you want to log out?", preferredStyle: .Alert)

    let defaultAction = UIAlertAction(title: "Yes", style: .Default, handler: nil)
    alertController.addAction(defaultAction)

    let defaultAction2 = UIAlertAction(title: "No", style: .Cancel, handler: nil)
    alertController.addAction(defaultAction2)

    self.presentViewController(alertController, animated: true, completion: nil)

    let VC = self.storyboard?.instantiateViewControllerWithIdentifier("loginscreen") as! ViewController //The file that controls the view

    self.presentViewController(VC, animated: true, completion: nil)


}

如您所见,我想在按下注销按钮时注销用户。当用户单击注销时,UIalert 弹出窗口询问他们是否确定要注销,但是当我单击“确定”时,它不会切换回登录界面 ViewController。

谁能帮帮我?

最佳答案

如果最后两行表示您要呈现的 View ,那么您必须在"is"按钮操作的处理程序中执行此代码:

let defaultAction = UIAlertAction(title: "Yes", style: .Default, handler: { _ in
    let VC = self.storyboard?.instantiateViewControllerWithIdentifier("loginscreen") as! ViewController //The file that controls the view

    self.presentViewController(VC, animated: true, completion: nil)
})

alertController.addAction(defaultAction)

关于ios - 单击警报按钮不起作用时更改 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38658279/

相关文章:

ios - 推送 UIViewController 的辅助方法

ios - 如果 Objective-C 文件包含 Project-Swift.h 的导入,如何将其导入到桥接 header

ios - 如何以编程方式快速切换到暗模式

ios - 将 NSMutableArray 的内容保存到文件

iOS 9.1 在辅助功能检查器打开时崩溃应用程序

ios - 如何在 iOS 中快速使用 UDP 套接字?

swift - 如何将 'nil' 设置为 [String : String] dictionary is valid? 的值

swift - 从全局变量填充文本字段失败

swift - Xcode I Collection View 我在 cellForRowAtIndexpath 函数中对 urlsession 数据任务进行排队

ios - UITextField 上的 UITapGestureRecognizer 在 IOS 7.1 中不再有效