1. 程式人生 > >swift3.0提示框新用法

swift3.0提示框新用法

var alert: UIAlertController!

            alert = UIAlertController(title: "提示", message: "新增照片", preferredStyle: UIAlertControllerStyle.actionSheet)

let cleanAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel,handler:nil)

let photoAction = UIAlertAction(title: "拍照", style:

UIAlertActionStyle.default){ (action:UIAlertAction)in

//填寫需要的響應方法

            }

let choseAction = UIAlertAction(title: "從手機相簿選擇", style: UIAlertActionStyle.default){ (action:UIAlertAction)in

//填寫需要的響應方法

            }

            alert.addAction(cleanAction)

            alert.addAction(photoAction)

            alert.addAction(choseAction)

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

或者是這種的

let alertVC : UIAlertController!

        alertVC  = UIAlertController.init(title: "退出登入", message: "確定退出登入?", preferredStyle: UIAlertControllerStyle.actionSheet)

let falseAA : UIAlertAction

= UIAlertAction.init(title: "取消", style: .cancel, handler: { (alertAction) in

NSHelper.showAlertTitle("你的乘車備案沒有結束,請結束後再退出", message: "", cancel: "確定")

        })

let trueAA : UIAlertAction = UIAlertAction.init(title: "確定", style: .default, handler: { (alertAction) in

AppSetting.setLoginYesFlag(status: "0")

let_ = self.navigationController?.popToRootViewController(animated: true)

        })

        alertVC.addAction(falseAA)

        alertVC.addAction(trueAA)

self.present(alertVC, animated: true, completion: nil)