UIActionSheet,UIAlertView,UIAlertController的详细说明

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

  • 1.中间展示(两种写法)
UIActionSheet,UIAlertView,UIAlertController的详细说明_第1张图片
中间展示
 //第一种方法
  1.挂代理
  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中写法)
UIActionSheet,UIAlertView,UIAlertController的详细说明_第2张图片
下面展示
//第一种方法
1.第一种挂代理
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];

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

你可能感兴趣的:(UIActionSheet,UIAlertView,UIAlertController的详细说明)