首页 > 其他 > 详细

UIAlertControl的使用对比与UIAlertView和UIActionSheet

时间:2015-04-25 13:36:15      阅读:146      评论:0      收藏:0      [点我收藏+]

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

原文:http://www.cnblogs.com/li--nan/p/4455702.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!