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];

}

  

时间: 2024-07-31 06:43:07

UIAlertControl的使用对比与UIAlertView和UIActionSheet的相关文章

iOS8以后UIAlertView和UIActionSheet两种alert页面都将通过UIAlertController来创建

1. Important: UIAlertView is deprecated in iOS 8. (Note that UIAlertViewDelegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert. //UIAlertView和UI

UIAlertView和UIActionSheet

##UIAlertView和UIActionSheet ```objc// cancelButton buttonIndex == 1// destructiveButton buttonIndex ==0 UIActionSheet *sheet =[[UIActionSheet alloc]initWithTitle:@"确定注销吗" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@&q

iOS开发——UI篇Swift篇&UIAlertView/UIActionSheet

UIAlertView/UIActionSheet UIAlertView 1 //一个按钮的提醒 2 @IBAction func oneButtonAler() 3 { 4 //创建单一按钮提醒视图 5 let oneButtonAlert:UIAlertView = UIAlertView(title: "提醒", message: "这是一个简单的提醒视图", delegate: nil, cancelButtonTitle: "确定")

UIAlertView及UIActionSheet 在ios8极其以下版本的兼容问题解决方案

本文转载至 http://www.aichengxu.com/view/35326 UIAlertView及UIActionSheet在ios8中被放弃,其功能将完全由UIAlertController代替: 1.Alert用法 UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"This is Title" message:@"This is message" prefer

iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?

太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的漂亮人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. 弃用了! 如今得用 UIAlertController 了. 使用两个样式来相应这两个控件: UIAlertView - UIAlertContr

IOS学习第二课 UIAlertView和UIActionSheet

1    UIAlertView 类似于Android中的Dialog,简单用法如下: UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Messate" delegate:nil cancelButtonTitle:@"Cancle" otherButtonTitles:nil, nil]; [alertView show]; 2   U

IOS UIAlertView 和 UIActionSheet的区别

UIAlertView 和 UIActionSheet的区别: 1.弹框位置不同: UIAlertView弹框显示在中间 UIActionSheet弹框显示在底端 2.是否可以实现文本框的输入(参考:http://www.ithao123.cn/content-9409772.html) UIAlertView可以实现,而UIActionSheet不可以实现. #import "RootViewController.h" @interface RootViewController ()

iOS:简单使用UIAlertVIew和UIActionSheet

做iOS开发的同学想必都用过UIAlertVIew或者UIActionSheet.UIAlertVIew 可以弹出一个出现在屏幕中间的提示视图,给用户展示信息,并让用户自己选择操作,UIActionSheet可以弹出一个选择列表,让用户选择列表中的某一项操作.使用UIAlertVIew和UIActionSheet非常简单,以下是一个简单的示例代码: //UIAlertView - (void)someButtonClicked {//初始化AlertView UIAlertView *alert

在iOS8.0之后的UIAlertView和UIActionSheet的新写法

在iOS8.0之后,苹果更新了UIAlertView和UIActionSheet的创建方法.在以前的版本中,这两个提醒用户的控件各自有自己的创建方法,但是在iOS8.0之后,使用了UIAlertController这个控制器类统一创建.不过之前的创建方法并没有在iOS8.0之后的版本中实效,依然可以正常使用.下边就记录下新的写法. 首先看苹果API的示例写法: UIAlertController* alert = [UIAlertController alertControllerWithTit