0

我有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)
    }
}
4

1 回答 1

2

由于您的警报已被解除并且您再次尝试解除警报,因此不会调用您的完成处理程序。

actionMainController.dismiss(animated: true) {

     self.showDeleteActionSheet()
}

相反,您应该在 Action 的完成处理程序上做一些工作

let deleteAction = UIAlertAction(title: "Delete Photo", style: .destructive) { (action) in

    self.showDeleteActionSheet() 
 }
于 2016-11-11T12:41:29.287 回答