三、iOS8之后的弹窗指示器
2015-07-02 23:35
471 查看
在用户使用App进行一些危险性操作时,使用对话框的形式提示用户能起到很为用户着想的作用。经常使用的对话框有以下两种:UIActionSheet 和 UIAlertView。但在ios8之后 UIActionSheet 和 UIAlertView都定义为过时了,官方文档解释:
UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead
以下就是常用两种对话框的基本使用:
// 第一种方式
// 创建弹框指示器
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请确定要取消吗?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
// 弹框提示
[sheet showInView:nil];
// 使用 UIActionSheet的代理方法进行相关操作
#pragma mark - actionSheet的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
if (buttonIndex == 0) {// 点击确定按钮
// 写上需要进行相关操作的代码
}
// 第二种方式
// 创建对话框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"亲,确定要注销吗?" preferredStyle:UIAlertControllerStyleActionSheet];
// 创建取消按钮
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// 相关操作
}];
// 创建确定按钮
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
// 回调方法
[self.navigationController popViewControllerAnimated:YES];
}];
// 添加按钮到对话框
[alert addAction:cancelAction];
[alert addAction:sureAction];
// 显示对话框
[self presentViewController:alert animated:YES completion:^{
// 完成显示后的相关操作
}];
UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead
以下就是常用两种对话框的基本使用:
// 第一种方式
// 创建弹框指示器
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请确定要取消吗?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
// 弹框提示
[sheet showInView:nil];
// 使用 UIActionSheet的代理方法进行相关操作
#pragma mark - actionSheet的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
if (buttonIndex == 0) {// 点击确定按钮
// 写上需要进行相关操作的代码
}
// 第二种方式
// 创建对话框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"亲,确定要注销吗?" preferredStyle:UIAlertControllerStyleActionSheet];
// 创建取消按钮
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// 相关操作
}];
// 创建确定按钮
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
// 回调方法
[self.navigationController popViewControllerAnimated:YES];
}];
// 添加按钮到对话框
[alert addAction:cancelAction];
[alert addAction:sureAction];
// 显示对话框
[self presentViewController:alert animated:YES completion:^{
// 完成显示后的相关操作
}];
相关文章推荐
- iOS NSAttributedString所有文本属性详解(多图)
- iOS 用instancetype代替id作返回类型有什么好处?
- iOS Core Data 简单封装
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- IOS中定时器NSTimer的开启与关闭
- iOS学习笔记(10下)六种手势
- iOS学习笔记(10)上 CABasicAnimation类使用
- iOS学习笔记(8)UserInteractionEnabled
- iOS学习笔记(7)视图控制器之间传递参数的三种方式
- iOS学习笔记 (5)NSDate和NSTimer
- 使用LeanClound(AVOS)造成的ios linker command failed with exit code 1 (use -v to see invocation)
- IOS页面自动布局 之 NSLayoutConstraint基础篇
- iOS9适配系列教程
- iOS9适配系列教程
- iOS 详解CoreLocation定位服务
- IOS 百度地图一直报 manager start failed!
- IOS 8.1.3 GameCenter code15 沙盒无法登陆
- 解决Xcode升级导致插件不管用的问题
- iOS---设备的唯一标识详解
- 我为什么要学IOS?