2016-11-11 73 views
0

我有PhotoBrowser(它从UIViewController继承)作为presentedViewController。我从UITableViewController提出。当我点击按钮时,PhotoBrowser呈现actionMainController(它继承自UIAlertController)。我想调用另一个UIAlertController,当我在actionMainController中选择其中一个动作并在其被解除后立即显示第二个UIAlertController但完成块不起作用。我想补充一点,驳回actionMainController成功,它的工作原理耗尽完成块不起作用。 Swift

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) 
    } 
} 
+0

行动的完成处理一些工作,把一个断点在那里,它被调用? – Tj3n

+0

从哪个类调用deletePhoto方法? –

+0

@Tj3n断点没有调用 – Alexander

回答

1

你完成处理程序不被调用,因为您的警报已经被解雇,你又试图解除警报。

actionMainController.dismiss(animated: true) { 

    self.showDeleteActionSheet() 
} 

相反,你应该做的是

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

    self.showDeleteActionSheet() 
}