How to create uialertcontroller in global swift

后端 未结 12 1729
情深已故
情深已故 2020-12-05 12:09

I\'m trying to create uialertcontroller in Config.swift file as follow.

static func showAlertMessage(titleStr:String, messageStr:St         


        
12条回答
  •  佛祖请我去吃肉
    2020-12-05 12:52

    I created a alerMessage class .I can call any where in my application

    //Common Alert Message Class 
    
    class AlertMessage {
    
    internal static var alertMessageController:UIAlertController!
    
    internal static func disPlayAlertMessage(titleMessage:String, alertMsg:String){
    
    
        AlertMessage.alertMessageController = UIAlertController(title: titleMessage, message:
            alertMsg, preferredStyle: UIAlertControllerStyle.Alert)
    
        AlertMessage.alertMessageController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default,handler: nil))
        if let controller = UIApplication.sharedApplication().keyWindow?.rootViewController?.presentedViewController {
            controller.presentViewController(AlertMessage.alertMessageController, animated: true, completion: nil)
        }
        else{
            UIApplication.sharedApplication().delegate?.window!!.rootViewController?.presentViewController(AlertMessage.alertMessageController, animated: true, completion: nil)
        }
    
        return
    
     }
    }
    

提交回复
热议问题