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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WangQingLei0307/article/details/64442942
第一种,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 不能使用
第一种和第二种用法没有限制,只是第一种并不常用,用哪种看大家选择
posted @ 2018-09-04 14:20  sundaysios  阅读(486)  评论(0)    收藏  举报