最新下载
热门教程
- 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.. } } | |
自己在手机上测过,可用!
相关文章
- 密室逃脱模拟器2无限之门开启方法 12-05
- 梦之形攻速飞弹书妹玩法攻略分享 12-05
- 密室逃脱模拟器2墙上的苍蝇谜题攻略 12-05
- 魔理沙还书茨木华扇彩蛋位置一览 12-05
- 影色渐染阿斯林顿的妹神官武器选择攻略 12-05
- Cleared Hot不同图标含义介绍说明 12-05