ios - 尝试在 Swift 中使用警报操作切换到另一个 View Controller

标签 ios swift

在我的代码中,我有一个允许用户登录或注册的操作表。当用户按下其中任何一个时,我想定义一个处理程序,将它们连接到登录/注册 View Controller 。我对此很陌生,所以我不太确定我做错了什么,但在我的代码中我收到一个错误,指出类型不可转换。代码如下所示:

let actionSheet = UIAlertController(title: "Do you have an account?", message: "Please Log-In or Sign-Up", preferredStyle: .ActionSheet)
    if let presentationController = actionSheet.popoverPresentationController {
        presentationController.sourceView = sender as UIView
        presentationController.sourceRect = sender.bounds
    }

    let dismissHandler = {
        (action: UIAlertAction!) in
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    let signupHandler = ({
        (ViewController: UIViewController!) in
        let signupVC: nextViewController = segue.signupVC as nextViewController
    })
    let loginHandler = ({
        (ViewController: UIViewController!) in
        let loginVC: nextViewController = segue.loginVC as nextViewController
    })
    actionSheet.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: dismissHandler))
    actionSheet.addAction(UIAlertAction(title: "Log-In", style: .Default, handler: dismissHandler))
    actionSheet.addAction(UIAlertAction(title: "Sign-Up", style: .Default, handler: signupHandler))
    presentViewController(actionSheet, animated: true, completion: nil)

}

任何帮助将不胜感激!提前致谢。

最佳答案

我不知道 segues 但我通常只是像这样展示它们:

let loginVC = LoginViewController()
self.presentViewController(loginVC, animated: true, completion: nil)

关于ios - 尝试在 Swift 中使用警报操作切换到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27107938/

相关文章:

iOS Swift 3 将值存储到 Realm

iOS - 隐藏在键盘下的 UIAlertController

ios - 如何按字母顺序对二维数组中的数据进行排序?

ios - 在 Swift 中连接字符串

ios - 如何通过按钮更新分配给自定义单元格中索引路径的核心数据

ios - 将自定义键盘嵌入 uiview

swift - 没有这样的模块 '####'

iphone - iOS - UITableView 正确刷新表格?

使用 Tasty Imitation Keyboard 在 Swift 中以编程方式使用 iOS 键盘

iOS Swift 方法在 obj C 项目上调用