四步曲:
1、创建UIAlertController 警告控制器
2、创建UIAlertAction 警告行为
3、将UIAlertAction 添加到UIAlertController
4、present出UIAlertController 警告控制器
直接上代码
import@H_502_49@ UIKit
@H_502_49@
class@H_502_49@ ViewController: UIViewController@H_502_49@ {
@H_502_49@
var controller:@H_502_49@UIAlertController?
@H_502_49@
@H_502_49@ override@H_502_49@ func@H_502_49@ viewDidLoad() {
super.@H_502_49@viewDidLoad()
@H_502_49@
@H_502_49@controller = @H_502_49@UIAlertController(
title: @H_502_49@"Choose how you would like to share this photo",
message: @H_502_49@"You cannot bring back a deleted photo",
@H_502_49@ preferredStyle: .ActionSheet@H_502_49@)
@H_502_49@
@H_502_49@ let@H_502_49@ actionEmail = UIAlertAction@H_502_49@(title: "Via email"@H_502_49@,
style: @H_502_49@UIAlertActionStyle.@H_502_49@Default,
@H_502_49@ handler: {(paramAction:UIAlertAction@H_502_49@!) in
@H_502_49@/* Send the photo via email */
@H_502_49@ })
@H_502_49@
@H_502_49@ let@H_502_49@ actionImessage = UIAlertAction@H_502_49@(title: "Via iMessage"@H_502_49@,0)"> @H_502_49@/* Send the photo via iMessage */
@H_502_49@ })
@H_502_49@
@H_502_49@ let@H_502_49@ actionDelete = UIAlertAction@H_502_49@(title: "Delete photo"@H_502_49@,175)"> style: @H_502_49@UIAlertActionStyle.@H_502_49@Destructive,0)"> @H_502_49@/* Delete the photo here */
@H_502_49@ })
@H_502_49@
@H_502_49@ controller@H_502_49@!.addAction@H_502_49@(actionEmail)
@H_502_49@ controller@H_502_49@!.addAction@H_502_49@(actionImessage)
@H_502_49@ controller@H_502_49@!.addAction@H_502_49@(actionDelete)
@H_502_49@
@H_502_49@ }
@H_502_49@
@H_502_49@ override@H_502_49@ func@H_502_49@ viewDidAppear(animated: Bool@H_502_49@) {
@H_502_49@ super@H_502_49@.viewDidAppear@H_502_49@(animated)
@H_502_49@ self@H_502_49@.presentViewController@H_502_49@(controller@H_502_49@!,animated: true@H_502_49@,completion: nil@H_502_49@)
@H_502_49@ }
@H_502_49@
@H_502_49@}