zoukankan      html  css  js  c++  java
  • 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:@"请假
    选择请假类型" 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];
        
    }
    

      

  • 相关阅读:
    java作用域public ,private ,protected 及不写时的区别
    Android开发环境部署
    java的WebService实践(cxf)
    Servlet小试
    XML内容作为String字符串读取报错
    myeclipse安装svn插件的多种方式
    一个简单的SpringMVC3 程序
    VS2010调试生成的文件
    双系统启动项修复
    安装服务命令
  • 原文地址:https://www.cnblogs.com/li--nan/p/4455702.html
Copyright © 2011-2022 走看看