为什么完成不起作用?完成问题
Why is the completion not working? completion issue
为什么完成不起作用?
警报出现后,它不会过渡到另一个 viewController
self.present(self.alertController2, animated: true, completion: {
self.performSegue(withIdentifier:"goToLogin", sender: self)
})
您应该先编写代码移动到新的视图代码运行然后在主线程中显示警报以显示警报。
DispatchQueue.main.async {
// AlertView.showAlert(title: Messages.Network.title, message: Messages.Network.message)
// }
Self.present
用于将此操作添加到视图中。您需要将此代码添加到您的 handler
处理程序中 mean It means what will I do when you click OK
let alertbutton = UIAlertAction(title: "OK", style: .destructive, handler: {
(UIAlertAction) in
self.performSegue(withIdentifier: "your id", sender: self)
})
完整示例:
let alert = UIAlertController(title: "Its empty", message: "Going another view", preferredStyle: .alert)
let alertaction = UIAlertAction(title: "OK", style: .destructive, handler: { (UIAlertAction) in
self.performSegue(withIdentifier: "your segue id", sender: self)
})
alert.addAction(alertaction)
self.present(alert, animated: true, completion: nil)
为什么完成不起作用?
警报出现后,它不会过渡到另一个 viewController
self.present(self.alertController2, animated: true, completion: {
self.performSegue(withIdentifier:"goToLogin", sender: self)
})
您应该先编写代码移动到新的视图代码运行然后在主线程中显示警报以显示警报。
DispatchQueue.main.async {
// AlertView.showAlert(title: Messages.Network.title, message: Messages.Network.message)
// }
Self.present
用于将此操作添加到视图中。您需要将此代码添加到您的 handler
处理程序中 mean It means what will I do when you click OK
let alertbutton = UIAlertAction(title: "OK", style: .destructive, handler: {
(UIAlertAction) in
self.performSegue(withIdentifier: "your id", sender: self)
})
完整示例:
let alert = UIAlertController(title: "Its empty", message: "Going another view", preferredStyle: .alert)
let alertaction = UIAlertAction(title: "OK", style: .destructive, handler: { (UIAlertAction) in
self.performSegue(withIdentifier: "your segue id", sender: self)
})
alert.addAction(alertaction)
self.present(alert, animated: true, completion: nil)