警告框和操作表(ActionSheet)
来源:互联网 发布:linux 查看cpu日志 编辑:程序博客网 时间:2024/06/05 01:02
iOS 开发中,应用程序如何实现与用户的交流呢?警告框和操作表就是为此设计的。
警告框时UIAlertView创建的,用于为用户以警告或提示,最多有两个按钮,超过两个就应该考虑使用操作表。由于在iOS中,警告框是”模态“(表示的是不关闭它就不能做别的事情),因此不应该随意使用,一般情况下,警告框的使用场景有如下几个:
-应用不能继续进行。例如,无法获得网络数据或者功能不能完成的时候,给用户一个警告,这种警告框只需一个按钮。
-询问另外的解决方案。好多应用在不能继续运行时,会给出另外的解决方案,让用户去选择。例如,WiFi网络无法连接时,是否使用3G网络。
-询问对操作的授权。当应用访问用户的一些隐私信息时,需要用户授权,例如用户当前的位置;通讯录或者日程表等。
AlertView的用法注意:
方法中实例化UIAlertView的对象时,最常用的构造函数是initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:,其中delegate参数场设置为self,既警告框的委托对象为当前的视图控制器(ViewController);cancelButtonTitle参数用于设置“取消”按钮的标题,它是警告框的左按钮;otherButtonTitles参数是其他按钮,它是一个字符串数组,该字符串数组以nil结尾。
从用户体验上讲,警告框的按钮不能多于两个。
当用户警告框只有一个按钮时,只是为了关闭警告框,这时不需要指定委托参数。但是有两个按钮的情况下,为了响应点击警告框的需要,常需要设置委托。
ActionSheet的用法注意:
如果想给用户提供多于两个的选择,
如上图所示,就应该使用操作表。
操作表是UIActionSheet创建的,在iPhone下运行会从屏幕下方滑出来,其布局是最下面是一个“取消”按钮“,它离用户的大拇指最近,最容易点到。如果选中有一个破坏性的操作,将会放在最上面,是大拇指最不容易碰到的位置,并且其颜色是红色的。
注意在iPad中,操作表的布局与iPhone有所不同,在iPad中,操作表不是从底部滑出来的,而是随机出现在触发它的按钮周围。此外,它还没有”取消“按钮,即便是在程序中定义了”取消“按钮,也不会显示它。
在实例化UIActionSheet对象时,最常用的构造函数是initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:。
UIActionSheet的actionSheetStyle属性德用于设定操作表的样式:
UIActionSheetStyleAutomatic。自动样式。
UIActionSheetStyleDefault。默认样式。
UIActionSheetStyleBlackTranslucent。半透明样式。
UIActionSheetStyleBlackOpaque。透明样式。
本次实例:
//
// ViewController.h
// 1006AlertViewAndActionSheet(操作表)
//
// Created by weibiao on 15-10-6.
// Copyright (c) 2015年 weibiao. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)testAlertView:(id)sender;
- (IBAction)testActionSheet:(id)sender;
@end
//
// ViewController.m
// 1006AlertViewAndActionSheet(操作表)
//
// Created by weibiao on 15-10-6.
// Copyright (c) 2015年 weibiao. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UIAlertViewDelegate,UIActionSheetDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)testAlertView:(id)sender {
UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"Alert"message:@"Alert text goes here"delegate:selfcancelButtonTitle:@"NO"otherButtonTitles:@"YES",nil];
[alert show];
NSLog(@"test alert");
}
- (IBAction)testActionSheet:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheetalloc] initWithTitle:@"ActionSheet"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"毁坏性按钮"otherButtonTitles:@"FaceBook",@"新浪微博",nil];
actionSheet.actionSheetStyle =UIActionSheetStyleAutomatic;
[actionSheet showInView:self.view];
}
@end
- 警告框和操作表(ActionSheet)
- 【iOS】动作表ActionSheet和警告框AlterView
- 操作表ActionSheet和警报AlertView
- Iphone开发(六)IOS中的通知--操作表ActionSheet和警报AlertView
- Iphone开发(六)IOS中的通知--操作表ActionSheet和警报AlertView
- Iphone开发(六)IOS中的通知--操作表ActionSheet和警报AlertView
- Iphone开发(六)IOS中的通知--操作表ActionSheet和警报AlertView
- IOS中的通知--操作表ActionSheet和警报AlertView
- IOS中的通知--操作表ActionSheet和警报AlertView
- IOS中操作表ActionSheet
- iOS警告框和操作表
- 警告框和操作表的使用方法
- 004_跨平台开发_MUI_操作表(actionsheet)
- IOS操作表和警告
- swift学习笔记之警告框和操作表
- 161,使用UIAlertControl创建警告框和操作表
- (十)弹出框Alert与ActionSheet
- Objective-C: UIKit:UITextFiled、UIAlertController(警告框、操作表)、
- php常用验证函数
- MySQL运算符和函数
- 《Effective STL》条款1-条款2
- GitHub上README.md教程
- Defining BJT Noise Equations
- 警告框和操作表(ActionSheet)
- sap用户出口 badi查询程序(通过事务代码)
- Ubuntu14.04中编译安装maliit-0.94-qt4
- 机器学习(一)监督学习
- 内部类
- 【动态域名解析工具】tunnel,国内版的ngrok,花生壳可以睡觉了
- 跨IE和Chrome浏览器事件处理的解决办法
- Error : android studio 中mipmap引用.9图片出错
- 总结自定义控件时用到的移动View对象的方法