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];


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

目录
相关文章
UIAlertView添加textField
UIAlertView添加textField
84 0
UINavigationController和UITabBarController合用。
UINavigationController和UITabBarController合用。
81 0
|
Android开发 iOS开发 HTML5
iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?
iOS 8 中 UIAlertView 和 UIActionSheet 河里去了? 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
1216 0