UIAlertControl的使用对比与UIAlertView和UIActionSheet
1.UIAlertVIew以-(void)show的方法显示:
- (void)viewDidLoad {
[super viewDidLoad];
//UIAlertView的使用
[self showAlert];
//UIAcyionSheet使用
// [self showAction];
#pragma mark [self showAlertController];方法不可以放在此处因为UIAlertControl继承与UIViewController
//UIAlertControl的使用
// [self showAlertController];
}
UIAlertView 的实现:
-(void)showAlert{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"紧急通知" message:@"由于幸福指数哦不断下降,经调查和假期成线性关系,特批以后工作一天休息一天" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alertView.alertViewStyle = UIAlertViewStyleDefault;
/*
UIAlertViewStyleDefault ,默认
UIAlertViewStyleSecureTextInput, 密码输入框
UIAlertViewStylePlainTextInput, 文本输入框
UIAlertViewStyleLoginAndPasswordInput 用户及密码
*/
[alertView show];
}
#pragma mark - UIALertDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
case 0:
NSLog(@"点击%ld",buttonIndex);
break;
case 1:
NSLog(@"点击%ld",buttonIndex);
break;
default:
break;
}
}

2.UIActionSheet的使用
-(void)showAction{
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"请假\n选择请假类型" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"事假" otherButtonTitles:@"病假",@"产假", nil];
[actionSheet showInView:self.view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark UIActionSheetDelegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
switch (buttonIndex) {
case 0:
NSLog(@"点击%ld",buttonIndex);
break;
case 1:
NSLog(@"点击%ld",buttonIndex);
break;
case 2:
NSLog(@"点击%ld",buttonIndex);
break;
default:
break;
}
}

3.UIAlertControl的简单使用
-(void)showAlertController{
//UIAlertControllerStyle两种类型UIAlertControllerStyleAlert类似UIAlertView
//UIAlertControllerStyleActionSheet类似UIActionSheet
UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"you and me" message:@"together forever" preferredStyle:UIAlertControllerStyleAlert];
//block代码块取代了delegate
UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"No matter of life and death" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"生死相依");
}];
UIAlertAction *alertTwo = [UIAlertAction actionWithTitle:@"Share weal and woe" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"同甘共苦");
}];
UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Sure" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"确定");
}];
[alertControl addAction:actionOne];
[alertControl addAction:alertTwo];
[alertControl addAction:alertthree];
//UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
[alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.text = @"for love ";
}];
[self presentViewController:alertControl animated:YES completion:nil];
}

UIAlertControl的使用对比与UIAlertView和UIActionSheet的更多相关文章
- UIAlertView、 UIActionSheet
一.UIAlertView. UIActionSheet都是ios系统自带的弹出式对话框,当UIAlertView或UIActionSheet弹出来时用户无法与应用界面中的其它控件交互,UIAlert ...
- iOS开发——UI篇Swift篇&UIAlertView/UIActionSheet
UIAlertView/UIActionSheet UIAlertView //一个按钮的提醒 @IBAction func oneButtonAler() { //创建单一按钮提醒视图 let on ...
- UIAlertView、UIActionSheet兼容iOS8
链接地址:http://blog.csdn.net/nextstudio/article/details/39959895?utm_source=tuicool 1.前言 iOS8新增了UIAlert ...
- 用block将UIAlertView与UIActionSheet统一起来
用block将UIAlertView与UIActionSheet统一起来 效果 1. 将代理方法的实例对象方法转换成了类方法使用 2. 要注意单例block不要长期持有,用完就释放掉 源码 https ...
- iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建
1. Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated. ...
- UIAlertView及UIActionSheet 在ios8极其以下版本的兼容问题解决方案
本文转载至 http://www.aichengxu.com/view/35326 UIAlertView及UIActionSheet在ios8中被放弃,其功能将完全由UIAlertControlle ...
- iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?
iOS 8 中 UIAlertView 和 UIActionSheet 河里去了? 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商 ...
- iOS:简单使用UIAlertVIew和UIActionSheet
做iOS开发的同学想必都用过UIAlertVIew或者UIActionSheet.UIAlertVIew 可以弹出一个出现在屏幕中间的提示视图,给用户展示信息,并让用户自己选择操作,UIActionS ...
- UIAlertView 与 UIActionSheet (提示用户)的使用方法
UIAlertView 提示用户 帮助用户选择框 // UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"警 ...
随机推荐
- C++智能指针及其简单实现
本文将简要介绍智能指针shared_ptr和unique_ptr,并简单实现基于引用计数的智能指针. 使用智能指针的缘由 1. 考虑下边的简单代码: int main() { ); ; } 就如上边程 ...
- TCP中的MSS解读(转)
本文摘录自TCP中的MSS解读. MSS 是TCP选项中最经常出现,也是最早出现的选项.MSS选项占4byte.MSS是每一个TCP报文段中数据字段的最大长度,注意:只是数据部分的字段,不包括TCP的 ...
- LeetCode之“链表”:Add Two Numbers
题目链接 题目要求: You are given two linked lists representing two non-negative numbers. The digits are stor ...
- 【cocos 2d-x】VS2012+win7+cocos2d-x3.0beta2开发环境配置
本系列文章由@二货梦想家张程 所写,转载请注明出处. 作者:ZeeCoder 微博链接:http://weibo.com/zc463717263 我的邮箱:michealfloyd@126.com ...
- Cursor类取出数据
重点是要调用 moveToFirst(); long id=intent.getLongExtra("id",0); Cursor cr =dbh.selectDataById(i ...
- Ibatis动态(dynamic)查询
Ibatis的动态查询使得数据操作变得非常的灵活,下次举出了常用的动态查询的属性信息: Ibatis配置信息 <!-- Dynamic Sql --> <typeAlias a ...
- Spring--FileSystemXmlApplicationContext
//从文件系统或者统一定位资源中获得上下文的定义 public class FileSystemXmlApplicationContext extends AbstractXmlApplication ...
- 未能加载文件或程序集“file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0
未能加载文件或程序集"file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framewor ...
- SharePoint2010 -- ECMAScript客户端模型简单示例
ECMAScript客户端模型,是SharePoint2010推出的三种客户端模型".NET托管"."ECMAScript"."Sliverlight ...
- Mac OS X版本的sublime text 3安装汇编语言语法支持
sublime是个好东西,小巧.功能强大而且跨平台! 不过默认的语法里没有对asm的支持,这让本猫情何以堪- 下面介绍一下Mac OS X中如何给sublime安装汇编的语法和自动汇编命令补全支持. ...