Swift UiAlertController在运行时接连不断

时间:2016-04-15 08:09:30

标签: swift uialertcontroller

我找到了解决问题的一些解决方案,以显示多个UIAlertController,但它们并不适合我。启动应用程序时,可能需要显示多个警报。因此,当我调用showAlert()函数时,我不知道是否会有更多警报。使用rootViewController.presentViewController(..),它只能显示一个,其他的将被忽略。所以我需要做的是检查是否出现了一个警报,否则排队警报,并在关闭第一个警报后检查是否有更多警报显示。我的想法是用NSOperation和NSOperationQueue解决这个问题,说只需要及时执行一个操作。像这样:

var alertQueue : NSOperationQueue = NSOperationQueue()    

func showAlert(alertController: UIAlertController) {
    alertQueue.maxConcurrentOperationCount = 1
    alertQueue.addOperation(NSOperationAlert(alertController: alertController))
}

NSOperation:

class NSOperationAlert: NSOperation {

    let aController : UIAlertController

    init(alertController : UIAlertController) {
        aController = alertController
    }

    override func start() { 
        AppRouter.sharedInstance.window.rootViewController?.presentViewController(aController, animated: true, completion: nil)
    }

}

但显然缺少一些东西。我不知道如何解决在另一个警报不再显示之后显示下一个排队警报的问题。换句话说,我怎么知道当前提供的警报已经完成"没有为每个按钮添加处理程序,并告诉我我的alertQueue执行下一个警报(如果有的话)。

非常感谢!

0 个答案:

没有答案