iOS 自带三种提示框使用、UIAlertView以及UIAlertController的使用

97 篇文章 0 订阅
79 篇文章 2 订阅

第一种,UIActionSheet 这种提示框我们平常很少使用,他的使用方法如下

UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:address
                                      delegate:self
                                      cancelButtonTitle:@"取消"
                                      destructiveButtonTitle:nil
                                      otherButtonTitles:@"高德地图中导航",@"苹果地图中导航",nil];//按钮显示可以设置多个按钮显示
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;//设置样式
[actionSheet showInView:self.view];
#pragma mark 打开地图导航
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
     if (buttonIndex == 0) {

     } else if(buttonIndex== 1) {

     } else if(buttonIndex == 2) {

     }
}
使用的前提我们导入一个协议才可以  
<UIActionSheetDelegate>

第二种,UIAlertView

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title
                                                   message:message
                                                  delegate:self
                                         cancelButtonTitle:@"取消"
                                         otherButtonTitles:@"确定", nil];
[alert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{//点击弹窗按钮后
    if (buttonIndex == 0) {//取消

    } else if (buttonIndex == 1){//确定

    }
}

第三种,UIAlertController

  

UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"总分:%d",_count*100] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"再玩一次" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnullaction) {

}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
 
以上三种都是自带的提示框
第三种会有一下限制,因为需要iOS需要8.0以上。所以为支持iOS 7.0 不能使用
第一种和第二种用法没有限制,只是第一种并不常用,用哪种看大家选择
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王 哪跑!!!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值