在我的代码中,我有一个允许用户登录或注册的操作表。当用户按下其中任何一个时,我想定义一个处理程序,将它们连接到登录/注册 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/