[英]Dissmiss completion block doesn't work. Swift
我有PhotoBrowser
(它继承自UIViewController
)作为presentedViewController
。 我从UITableViewController
呈现它。 当我点击按钮时, PhotoBrowser
显示actionMainController
(它继承自UIAlertController
)。 我想调用另一个UIAlertController
,当我在actionMainController中选择一个动作并在关闭它后立即显示第二个UIAlertController
,但是完成块不起作用时。 我想补充一下,关闭actionMainController
成功,它可以正常工作
class PhotoBrowser: SKPhotoBrowser {
// MARK: - Controllers
private var actionMainController = UIAlertController()
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - override var
override var prefersStatusBarHidden: Bool {
return true
}
// MARK: - functions
func editAvatar() {
debugPrint("removePhoto")
actionMainController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionMainController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
let deleteAction = UIAlertAction(title: "Delete Photo", style: .destructive) { (action) in
self.deletePhoto()
}
let takePhoto = UIAlertAction(title: "Take Photo", style: .default) { (action) in
}
let choosePhoto = UIAlertAction(title: "Choose Photo", style: .default) { (action) in
}
actionMainController.addAction(deleteAction)
actionMainController.addAction(takePhoto)
actionMainController.addAction(choosePhoto)
present(actionMainController, animated: true, completion: nil)
}
private func deletePhoto() {
actionMainController.dismiss(animated: true) {
// TODO: it
// self.showDeleteActionSheet()
}
showDeleteActionSheet()
}
private func showDeleteActionSheet() {
let deleteActionController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
deleteActionController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
let deleteAction = UIAlertAction(title: "Delete Photo", style: .destructive) { (action) in
}
deleteActionController.addAction(deleteAction)
present(deleteActionController, animated: true, completion: nil)
}
}
您的完成处理程序不会被调用,因为您的警报已被关闭,并且您再次尝试关闭该警报。
actionMainController.dismiss(animated: true) {
self.showDeleteActionSheet()
}
相反,您应该对Action的完成处理程序做一些工作,如下所示:
let deleteAction = UIAlertAction(title: "Delete Photo", style: .destructive) { (action) in
self.showDeleteActionSheet()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.