IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法

Author:hmjiangqq

Email:jiangqqlmj@163.com

在平时操作中,应用需要和用户进行交流:那么会用到下面两种视图控件

(1:警告视图UIAlertView,2:操作表视图UIActionSheet)

(一):警告视图:UIAlertView

首先看下官方解说:

Use the UIAlertView class to display an alert message to the user. An alert view functions similar to but differs in appearance from an action sheet (an   instance ofUIActionSheet).

Use the properties and methods defined in this class to set the title, message, and delegate of an alert view and configure the buttons. You must set a delegate if you add custom buttons. The delegate should conform to the UIAlertViewDelegate protocol.   Use the show method   to display an alert view once it is configured.

作用:提示用户,帮助用户和选择,用于警告或者提示。最多是两个按钮。

如果超过两个就应该使用第二种方式:操作表。

[注]在IOS开发中,警告框的权限比较高,所以我们不应该去随意的使用。一般情况下,

警告框使用的场景可以是如下的几个:

①:应用不能运行:例如:应用崩溃,或者无法获取数据,这里可以给用户一个警告。

②:询问用户:  例如:应用不能继续运行的时候,可以提示让用户去选择解决方案。

③:询问一些授权信息  :例如:我们的应用需要去访问以下用户的隐私数据,这里提示给

用户,方便用户选择。

④....等等其他场景。

UIAlertView的常用属性和方法:

实例代码如下:

-(void)showAlertView{     UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"other", nil];     [alertView show];     [alertView release];       NSLog(@"showAlertView..."); }

运行截图:


同时我们可以在创建的时候设置代理(Delegate)这边用self指定,为当前控制器实现代理方法:

UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"other", nil]; 实现方法如下: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{     NSLog(@"点击了:%@",[alertView buttonTitleAtIndex:buttonIndex]);      }

(二):操作表视图:UIActionSheet

看下官方解说:

Use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt   the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.

Use the properties and methods of this class to configure the action sheet’s message, style, and buttons before presenting it. You should also assign a delegate to your action sheet. Your delegate object is responsible for performing the action associated with   any buttons when they are tapped and should conform to the UIActionSheetDelegateprotocol.   For more information about implementing the methods of the delegate, see UIActionSheetDelegate   Protocol Reference.

用于给用户多个提示选择操作,例如在我们的应用中,我们需要把信息分享到微信,腾新微博

等多个平台,就应该使用操作表。操作表示是UIActionSheet创建,会从手机的屏幕底下滑出来。

UIActionSheet常用属性和方法

示例代码如下:

-(void)showActionSheet{     //操作表     UIActionSheet *actionSheet=[[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"按钮" otherButtonTitles:@"微信",@"新浪", nil]autorelease];     actionSheet.actionSheetStyle=UIActionSheetStyleBlackOpaque;     [actionSheet showInView:self.window];     NSLog(@"showActionSheet..."); } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{     NSLog(@"点击了:%@",[alertView buttonTitleAtIndex:buttonIndex]);      }

[注]:UIActionSheet的actionSheetStyle属性用于设定操作表的样式,样式风格如下:

typedefNS_ENUM(NSInteger,   UIActionSheetStyle) {

UIActionSheetStyleAutomatic        = -1,       // take appearance from toolbar style otherwise   uses 'default'

UIActionSheetStyleDefault          = UIBarStyleDefault, 默认样式

UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,  半透明

UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,  透明

};

运行截图:

转载于:https://blog.51cto.com/2939716/1376360

IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法...相关推荐

  1. IOS学习笔记(四)之UITextField和UITextView控件学习

    IOS学习笔记(四)之UITextField和UITextView控件学习(博客地址:http://blog.csdn.net/developer_jiangqq) Author:hmjiangqq ...

  2. iOS学习笔记-自己动手写RESideMenu

    代码地址如下: http://www.demodashi.com/demo/11683.html 很多app都实现了类似RESideMenu的效果,RESideMenu是Github上面一个stars ...

  3. iOS学习笔记-地图MapKit入门

    代码地址如下: http://www.demodashi.com/demo/11682.html 这篇文章还是翻译自raywenderlich,用Objective-C改写了代码.没有逐字翻译,如有错 ...

  4. iOS学习笔记-自定义过渡动画

    代码地址如下: http://www.demodashi.com/demo/11678.html 这篇笔记翻译自raywenderlick网站的过渡动画的一篇文章,原文用的swift,由于考虑到swi ...

  5. JavaScript学习笔记(九)(验证框架,layer弹出层)

    JavaScript学习笔记(九) 一.jQuery Validate验证框架 1.引入相关插件路径 2. 修改一些规则 3. 自定义验证规则 4.异步验证 整体代码 二.layer弹出层 1.引入相 ...

  6. iOS学习笔记22 推送通知

    ###一.推送通知 推送通知就是向用户推送一条信息来通知用户某件事件,可以在应用退到后台后,或者关闭后,能够通过推送一条消息通知用户某件事情,比如版本更新等等. ######推送通知的常用应用场景: ...

  7. Polyworks脚本开发学习笔记(九)-公差控制及制作报告

    Polyworks脚本开发学习笔记(九)-公差控制及制作报告 定义公差 系统有默认的公差设置,可以在选项中进行系统的默认设置,但往往不是想要的.比如下图的XYZ三向都是-/+1,我想只控制Y向并且公差 ...

  8. OpenCV for Ios 学习笔记(4)-标记检测1

    本文原始地址:OpenCV for Ios 学习笔记(4)-标记检测1 简单的标记经常是以白色块和黑色块构成的规则图形.因为我们预先知道这些因素,所以我们可以很容易检测标记. 如图: 首先,我们需要找 ...

  9. oracle 隐藏视图定义,【学习笔记】show hidden parameter 创建查看隐藏参数视图

    天萃荷净 分享一篇开发DBA常用的show hidden parameter,创建查看隐藏参数视图的案例步骤 1.创建查看隐藏参数视图(show_hidden_v$parameter) --conn ...

最新文章

  1. 自动驾驶的视觉感知包括哪些内容?
  2. 如何获得images.xcassets 中图片的路径?
  3. Quartz.Net进阶之四:CronTrigger 详述
  4. wxWidgets:滚动窗口
  5. golang为LigerUI编写简易版本web服务器
  6. Jupyter notebook的正确打开方式
  7. Python——rrdtool模块的安装
  8. 华为畅享max有没有人脸识别_华为三款5000mAh超大电池手机,都是续航王者,最低只要1499元...
  9. 突然想起来几年前我写的 !
  10. Tensorflow实现fashion-mnist数据集的图片识别项目代码
  11. Edraw的深化使用画网络拓扑图
  12. 复制高亮代码到印象笔记
  13. 在Ubuntu中安装中文输入法
  14. 计算机宏如何设置方法,excel 如何启用宏的方法,以及如何设置excel启用宏
  15. React SSR 服务器端渲染
  16. vscode自定义消息配置
  17. java.lang.AssertionError: Activity needs to be set if initial lifecycle state is resumed
  18. 计算机数据采集处理系统使用方法,数据采集与处理系统的要求
  19. 2022出海东南亚:马来西亚电商市场现状及网红营销特点
  20. VSC学习前端,不容错过的插件

热门文章

  1. mysql和oracle表的互导_oracle到mysql的导数据方式(适用于任意数据源之间的互导)...
  2. 大咖云集!航天智慧物流创意组-技术培训第三期
  3. 固态铝电解电容与液态铝电解电容
  4. 节能无线信标Ver0:功率测试
  5. STC8K28步进电机ULC2003触发器
  6. c语言数组怎么环形阵列,C语言 用于大阵列的无复制线程安全环形缓冲区
  7. 递增三元组蓝桥杯c语言,第九届蓝桥杯_递增三元组(枚举的优化思路)
  8. 图像迁移风格保存模型_CV之NS:图像风格迁移(Neural Style 图像风格变换)算法简介、关键步骤配图、案例应用...
  9. 跳至下一个断点_基金经理:DeFi将推动以太坊在下一个上涨周期中涨至9000美元...
  10. vim 代码跳转神器 YouComPlete