UIActionSheet,UIAlertView,UIAlertController的详细说明

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

  • 1.中间展示(两种写法)
中间展示
 //第一种方法
  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中写法)
下面展示
//第一种方法
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];

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,194评论 4 61
  • 【今天内容】 伙伴们中午好哇,都醒了么❤~ 001.上个礼拜六的现在,我们已经见面了,大家坐在一起,听金句李上蹿下...
    大爱赫敏阅读 1,703评论 0 0
  • 美乐爱觉日精进打卡374天 天呐,通过互联网行动派琦琦认识了那么多同频的小伙伴,孕妈妈,产后妈妈,都那么真诚,那么...
    曾小杰爱码字阅读 2,629评论 0 1
  • 逆风飞扬目录 他是我的读者。今年1月25日关注了我的公众号。之前,是没有任何交集的陌生人。 那时公众号刚刚打开赞赏...
    闻芯阅读 5,167评论 23 11
  • 古绝·勇者攀(新韵) 万里晴空耀雪山, 九曲回肠墨蠎盘。 恭迎壮士千秋树, 哪位儿郎踏顶欢?
    任尔风云我自逍阅读 799评论 0 3