首页 文章

检测UIAlertController何时被另一个UIViewController解雇

提问于
浏览
1

从iOS 8和新的UIAlertController开始,在以下场景中:

  • 呈现了UIAlertController .

  • 本地推送通知 Banner 显示在顶部,作为UIWindow .

  • 用户点击 Banner ,然后导航到另一个UIViewController,并且window.rootViewController正在关闭UIAlertController ......

有没有办法检测到任何未被任何UIAlertAction按钮激活的解雇?

1 回答

  • 0

    为了避免您的UIAlertViewController被新的UIViewController解雇,我的解决方案是: - 与水平= UIWindowALertLEvel 1创建新的UIWindow - 添加空RootViewController的为一个UIWindow - 作出这样的UIWindow一个keyWindow - 从RootViewController的表演alertController .

    因此,这个alertcontroller不会被另一个viewcontroller解雇 .

    我的代码:

    func showSimpleAlertOverWindow(title: String, msg: String, okButtonTitle : String, animated : Bool) {
            CLWrapper.logDebug("show message <\(msg)>")
    
            let _alertWindow = UIWindow(frame: UIScreen.mainScreen().bounds)
            _alertWindow.rootViewController = UIViewController()
            _alertWindow.windowLevel = UIWindowLevelAlert + 1
            _alertWindow.hidden = false
    
            let alert = UIAlertController(title: title ?? "", message: msg ?? "", preferredStyle: UIAlertControllerStyle.Alert)
            let okBtn = UIAlertAction(title: okButtonTitle ?? "", style: UIAlertActionStyle.Default) { (alertAction) -> Void in
                _alertWindow.resignKeyWindow()
                _alertWindow.hidden = true
    
            }
    
            alert.addAction(okBtn)
    
            _alertWindow.makeKeyWindow()
            _alertWindow.rootViewController!.presentViewController(alert, animated: animated, completion: nil)
    
        }
    

相关问题