swift中UIActionSheet的使用
2016-09-27 15:36
741 查看
// 方法1 let alertSheet = UIActionSheet(title: alertTitle, delegate: nil, cancelButtonTitle: alertOK, destructiveButtonTitle: alertCancel) alertSheet.showInView(self.view)
// 方法2
// 实例化时添加代理对象,同时注意添加协议
let alertSheet = UIActionSheet(title: alertTitle, delegate: self, cancelButtonTitle: alertOK, destructiveButtonTitle: alertCancel, otherButtonTitles: "警告", "提示", "通告")
alertSheet.showInView(self.view)
// 添加协议 class ViewController: UIViewController, UIActionSheetDelegate { override func viewDidLoad() { ... } ... }
// 代理方法 // MARK: UIActionSheetDelegate func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { let buttonTitle = actionSheet.buttonTitleAtIndex(buttonIndex) if buttonTitle == alertCancel { print("你点击了退出") } else if buttonTitle == alertOK { print("你点击了确定") } else { print("你点击了其他") } }
// 方法3
// 1 实例化
let alertSheet = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.ActionSheet)
// 2 命令(样式:退出Cancel,警告Destructive-按钮标题为红色,默认Default)
let cancelAction = UIAlertAction(title: alertCancel, style: UIAlertActionStyle.Cancel, handler: nil)
let deleteAction = UIAlertAction(title: "删除", style: UIAlertActionStyle.Destructive, handler: nil)
let archiveAction = UIAlertAction(title: alertOK, style: UIAlertActionStyle.Default, handler: {
action in
print("OK")
})
alertSheet.addAction(cancelAction)
alertSheet.addAction(deleteAction)
alertSheet.addAction(archiveAction)
// 3 跳转
self.presentViewController(alertSheet, animated: true, completion: nil)
相关文章推荐
- swift中UIAlertView的使用
- 如何隐藏tabbar顶部的黑线(swift)
- OC,Swift混合编程,包含String参数
- iOS Swift下dispatch_after的写法
- 自定义环形进度条UIAnnularProgress(Swift)
- Swift Web框架
- swift 去除数组里面重复的属性
- swift TabBarController内部控制的viewController视图被tabbar遮挡
- 获取xcdo内的所有2倍和3倍图片 或是 获取某文件夹下的所有2倍和3倍图片
- swift 二叉树排序
- Xcode8 Use Legacy Swift Language Version的错误解决
- swift基础学习传值[属性传值、代理、block代码块、等]
- swift App版本更新
- swift项目第四天:动态加载控制器
- iOS开发必知Swift结构体中实现写时复制的方法
- swift学习笔记 - 位移枚举的按位或运算
- Swift3.0 - 集合 - Set
- Swift - 真机调试正常,打包成IPA安装后一启动就闪退的问题解决
- Swift - 企业帐号进行IPA的打包、分发、下载安装的详细流程
- swift/OC 深拷贝 浅拷贝