swift中UIActionSheet的使用

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 方法1  
  2. let alertSheet = UIActionSheet(title: alertTitle, delegate: nil, cancelButtonTitle: alertOK, destructiveButtonTitle: alertCancel)  
  3. alertSheet.showInView(self.view)  


[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 方法2  
  2. // 实例化时添加代理对象,同时注意添加协议  
  3. let alertSheet = UIActionSheet(title: alertTitle, delegateself, cancelButtonTitle: alertOK, destructiveButtonTitle: alertCancel, otherButtonTitles"警告""提示""通告")  
  4. alertSheet.showInView(self.view)  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 添加协议  
  2. class ViewController: UIViewController, UIActionSheetDelegate {  
  3.       
  4.     override func viewDidLoad() {  
  5.         ...  
  6.     }  
  7.     ...  
  8. }  
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 代理方法  
  2. // MARK: UIActionSheetDelegate  
  3. func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) {  
  4.         let buttonTitle = actionSheet.buttonTitleAtIndex(buttonIndex)  
  5.         if buttonTitle == alertCancel  
  6.         {  
  7.             print("你点击了退出")  
  8.         }  
  9.         else if buttonTitle == alertOK  
  10.         {  
  11.             print("你点击了确定")  
  12.         }  
  13.         else  
  14.         {  
  15.             print("你点击了其他")  
  16.         }  
  17. }  

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. // 方法3  
  2. // 1 实例化  
  3. let alertSheet = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.ActionSheet)  
  4. // 2 命令(样式:退出Cancel,警告Destructive-按钮标题为红色,默认Default)  
  5. let cancelAction = UIAlertAction(title: alertCancel, style: UIAlertActionStyle.Cancel, handler: nil)  
  6. let deleteAction = UIAlertAction(title: "删除", style: UIAlertActionStyle.Destructive, handler: nil)  
  7. let archiveAction = UIAlertAction(title: alertOK, style: UIAlertActionStyle.Default, handler: {  
  8.             action in  
  9.             print("OK")  
  10. })  
  11. alertSheet.addAction(cancelAction)  
  12. alertSheet.addAction(deleteAction)  
  13. alertSheet.addAction(archiveAction)  
  14. // 3 跳转  
  15. self.presentViewController(alertSheet, animatedtrue, completion: nil)  



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值