最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
兼容ios7+ios8的alert消息提醒框
时间:2022-06-25 23:47:10 编辑:袖梨 来源:一聚教程网
不多说了,直接上代码,看代码注释内容吧
| 代码如下 | 复制代码 |
| if respondsToSelector("UIAlertController"){ var refreshAlert = UIAlertController(title: "注意", message: "确定要删除该信息吗?", preferredStyle: UIAlertControllerStyle.Alert) refreshAlert.addAction(UIAlertAction(title: "是", style: .Default, handler: { (action: UIAlertAction!) in //实际代码 } )) refreshAlert.addAction(UIAlertAction(title: "否", style: .Default, handler: nil)) presentViewController(refreshAlert, animated: true, completion: nil) } else { let at = UIAlertView() at.delegate = self at.title = "注意" at.message = "确定要删除该信息吗?" at.addButtonWithTitle("是") at.addButtonWithTitle("否") at.show() } | |
上面的代码,ios8下直接用UIAlertController,ios7下用UIAlertView。ios8的处理函数直接写在上面了,而ios7的需要实现代理的一个函数:
| 代码如下 | 复制代码 |
| func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){ switch buttonIndex{ case 0: //实际代码(选择是) break; case 1: //实际代码(选择否) break; default: //NSLog("Default"); break; //Some code here.. } } | |
自己在手机上测过,可用!
相关文章
- 小猿口算怎么免费领口算本 06-04
- 英文翻译软件推荐:2026热门实用的英文翻译工具排行榜 06-04
- 免费录屏软件推荐|高清稳定无水印的热门录屏工具大全 06-04
- 无广告免费影视软件推荐 热门高清追剧观影应用排行榜 06-04
- Gemini学生认证5个常见错误,避坑必看 06-04
- 推荐好用的搜索软件 免费下载高效实用的搜索工具 06-04