Swift

 

        let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)

        alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))

        self.presentViewController(alert, animated: true, completion: nil)

        alert.addAction(UIAlertAction(title: "lala", style: UIAlertActionStyle.Cancel, handler: { (action) in

            switch action.style{

            case .Default:

                print("default")

                

            case .Cancel:

                print("cancel")

                

            case .Destructive:

                print("destructive")

            }

        }))

        

        alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { action in

            switch action.style{

            case .Default:

                print("default")

                

            case .Cancel:

                print("cancel")

                

            case .Destructive:

                print("destructive")

            }

        }))

原文地址:https://www.cnblogs.com/ChouDanDan/p/5088989.html