UIAlertView笔记
来源:互联网 发布:淘宝卖家违规扣分 编辑:程序博客网 时间:2024/06/06 23:56
UIAlertView是创建一个用以给用户提示或者警告的提示框。能包含多个按钮。
UIAlertView是一个模态的(阻塞式),因此在应用中不应当频繁使用。一般应用场景:应用不能继续运行时;询问另外的解决方案;询问对操作的授权。
使用UIAlertView就需要实现UIAlertViewDelegate协议。这个协议是UIAlertView的委托协议。点击UIAlertView中的按钮会给委托对象发送alertView:clickedButtonAtIndex:消息。
相关实现代码如下:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"错误" message:@"用户名密码错误" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles: nil]; [alertView show];
在实例化UIAlertView对象时,最常用的方法是:initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:。其中delegate可以设定为self,即将警告框委托给当前所在的控制器,cancelButtonTitle参数用于设置“取消”按钮的标题,实际显示中是左侧的按钮。otherButtonTitles是除取消按钮以外的全部,以字符串数组的形式传入,最后一个数组为nil。
虽然可以通过otherButtonTitles来设定多个按钮,但一般一个警告框最多设定两个,否则影响用户体验。
监听用户按了哪个按钮可以通过alertView:clickedButtonAtIndex:进行实现。传入参数为整型数字,cancelButton为0,otherButton从做往右依次为1,2,3.....
0 0
- UIAlertView笔记
- 关于UIAlertView的笔记
- ios学习笔记 UIAlertView
- UIAlertView 开发笔记
- 【iOS学习笔记】UIalertview
- iOS学习笔记4-UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- UIAlertView
- LeetCode 之 Letter Combinations of a Phone Number
- java模板代码
- C# 事件委托 【开门两次 开枪】
- MQTT的学习研究(九)基于HTTP GET MQTT 抓取消息服务端使用
- “corruption in the heap” vector内存释放错误
- UIAlertView笔记
- C++标准库类型(转)
- 算法导论第15章 最优二叉树
- javascript获取光标位置以及设置光标位置(兼容firefox)
- 迭代器是什么
- 一,关于struts.xml参数
- 对“Halcon视频教程第一章 第二节”的学习感悟
- 利用Kprobe探测内核中的变量
- MD5算法原理、实现与作用