UIActionSheet,UIAlertView,UIAlertController的详细说明

简介: UIActionSheet,UIAlertView,UIAlertController的详细说明

特别说明:iOS8.3以后就升级为UIAlertController


  • 1.中间展示(两种写法)


image.png

//第一种方法
  1.挂代理<UIActionSheetDelegate>
  2.在点击的地方调用
  UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"全国统一客服热线4007-114-115" message:nil delegate:self cancelButtonTitle:@"拨打" otherButtonTitles:@"取消", nil];
  [alertView show];
  3.方法调用
  - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
 {
      if (buttonIndex == 0)
     {
          NSLog(@"拨打");
     }else if (buttonIndex == 1)
     {
           NSLog(@"取消");
     }  
 }
//第二种方法(方法里面直接调用:不用挂代理)
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"全国统一客服热线4007-114-115" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"拨打" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"拨打");
}];
UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
     NSLog(@"取消");
}];
[alertController addAction:alertAction];
[alertController addAction:alertAction2];
[self presentViewController:alertController animated:YES completion:nil];


  • 2.下面展示(2中写法)


image.png


//第一种方法
1.第一种挂代理<UIActionSheetDelegate>
2.在点击的地方调用
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从手机选择", @"拍照", nil];
sheet.actionSheetStyle = UIBarStyleDefault;
[sheet showInView:self.view];
3.方法调用
 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
 {
     if (buttonIndex == 0)
    {
           NSLog(@"我是从手机选择");
    }else if (buttonIndex == 1)
    {
           NSLog(@"我是拍照");
    }
 }
 //第二种方法(方法里面直接调用:不用挂代理)
  UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"从手机选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"从手机选择");
}];
UIAlertAction *alertAction1 = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
     NSLog(@"拍照");
}];
UIAlertAction *alertAction2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"取消");
}];
[alertController addAction:alertAction];
[alertController addAction:alertAction1];
[alertController addAction:alertAction2];
[self presentViewController:alertController animated:YES completion:nil];


喜欢的您就点个喜欢(谢谢)

目录
相关文章
|
4天前
|
iOS开发 UED 容器
navigationController 的使用详解
navigationController 的使用详解
|
12月前
|
Swift iOS开发
iPad上的ActionSheet
最近公司的应用要做iPad的适配,所以这两天一直在调整项目的大小。
|
iOS开发
UISearchBar去除背景
UISearchBar去除背景
113 0
UISearchBar去除背景
UIAlertView添加textField
UIAlertView添加textField
58 0
|
开发者 iOS开发
UIDatePicker的详细讲解
UIDatePicker的详细讲解
399 0
 UIDatePicker的详细讲解