Swift---UIAlertController封装
来源:互联网 发布:java 上传下载apk文件 编辑:程序博客网 时间:2024/05/16 05:02
import Foundationimport UIKitclass YJAlertControllerTool { /** alterController 两个按钮 处理otherBtn事件 - parameter currentVC: 当前控制器 - parameter meg: 提示消息 - parameter cancelBtn: 取消按钮 - parameter otherBtn: 其他按钮 - parameter handler: 其他按钮处理事件 */ static func showAlert(currentVC:UIViewController, meg:String, cancelBtn:String, otherBtn:String?, handler:((UIAlertAction) -> Void)?){// guard let vc = self.getCurrentVC() else{ return } dispatch_async(dispatch_get_main_queue(), { () -> Void in let alertController = UIAlertController(title:GFB_ALTER_MSG, message:meg , preferredStyle: .Alert) let cancelAction = UIAlertAction(title:cancelBtn, style: .Cancel, handler:nil) alertController.addAction(cancelAction) if otherBtn != nil{ let settingsAction = UIAlertAction(title: otherBtn, style: .Default, handler: { (action) -> Void in handler?(action) }) alertController.addAction(settingsAction) } currentVC.presentViewController(alertController, animated: true, completion: nil) }) } /** alterController 一个按钮 不处理事件,简单实用 - parameter currentVC: 当前控制器 - parameter meg: 提示消息 */ static func showAlert(currentVC:UIViewController, cancelBtn:String, meg:String){ showAlert(currentVC, meg: meg, cancelBtn: cancelBtn, otherBtn: nil, handler: nil) } /** 两个按钮 都处理事件 - parameter currentVC: 当前控制器 - parameter meg: 提示消息 - parameter cancelBtn: 取消按钮 - parameter otherBtn: 其他按钮 - parameter cencelHandler: 取消按钮事件回调 (不处理可不写,考虑到有些场合需要使用) - parameter handler: 其他按钮事件回调 */ static func showAlert(currentVC:UIViewController, meg:String, cancelBtn:String, otherBtn:String?,cencelHandler:((UIAlertAction) -> Void)?, handler:((UIAlertAction) -> Void)?){ dispatch_async(dispatch_get_main_queue(), { () -> Void in let alertController = UIAlertController(title:GFB_ALTER_MSG, message:meg , preferredStyle: .Alert) let cancelAction = UIAlertAction(title:cancelBtn, style: .Cancel, handler:{ (action) -> Void in cencelHandler?(action) }) alertController.addAction(cancelAction) if otherBtn != nil{ let settingsAction = UIAlertAction(title: otherBtn, style: .Default, handler: { (action) -> Void in handler?(action) }) alertController.addAction(settingsAction) } currentVC.presentViewController(alertController, animated: true, completion: nil) }) }}
0 0
- Swift---UIAlertController封装
- UIAlertController的使用(Swift)
- swift 的 UIAlertController使用
- Swift开发:UIAlertController 弹框
- Swift开发:UIAlertController 弹框
- iOS-UIAlertController简易封装
- iOS - 封装 - UIAlertController
- 封装一个UIAlertController
- UIAlertController简单封装
- Swift完成UIAlertController的调用
- Swift中UIAlertController的使用
- Swift基础之对话框UIAlertController
- 关于UIAlertController的使用(swift)
- Swift开发:弹框(UIAlertController)
- UIAlertController在Swift中的用法
- Swift - UIAlertController的简单使用
- Swift-->UIAlertController(对话框)的使用
- UIAlertController的延展(swift)
- FirstStrust2
- iOS 关于MD5容易遗漏的两个库
- Hadoop Hive基础sql语法
- 交叉编译知识解析(一) —— 交叉编译和交叉工具链
- 各大公司广泛使用的在线学习算法FTRL详解
- Swift---UIAlertController封装
- 爬坑小记---listview上图片加载实现三级缓存
- 华为机试--Java
- 飞马哥:正确推广模式框架的解析
- Receiver 分发详解
- Qt之QCryptographicHash
- 解决shell命令行只显示-bash-4.1#不显示用户和路径方法
- Android多渠道打包
- Receiver, ReceiverSupervisor, BlockGenerator, ReceivedBlockHandler 详解