[英]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.