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版MD5加密算法
    【Struts2复习知识点四】Path路径问题
    IE7与IE8浏览器下session cookie的共享问题以及区别
    【Struts2复习知识点八】DomaimModel域模型接收参数
    Activity class {package/class} does not exist及Unable to start activity ComponentInfo 解决方法
    【Struts2复习知识点二】namespace的配置
    【Struts2复习知识点五】ActionMethod 动态指定调用方法
    【Struts2复习知识点一】配置struts2环境
    JS面向对象编程
    【Struts2复习知识点三】Action的配置
  • 原文地址:https://www.cnblogs.com/li--nan/p/4455702.html
Copyright © 2011-2022 走看看