最新下载
热门教程
- 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.. } } |
自己在手机上测过,可用!
相关文章
- Pi币TRC20币圈都在用的安装包盘点 Pi币TRC20APP入门选择十大排名 06-09
- 当前最值得购买的加密货币,全球加密货币大规模采用率不断上升 06-09
- 《纸嫁衣6千秋魇》第三章肖医生的家进入方法 06-09
- 《重装机兵3》大破坏密码大全 06-09
- 《剑灵2》搬砖系统介绍 06-09
- 《三角洲行动》物资点搜索优先级推荐 06-09