zoukankan      html  css  js  c++  java
  • 提示窗UIAlertView与UIAlertController的用法(持续更新中)

    一般在if判断中加入

    1.第一种基础型

    全都在xxx.m功能文件中编写

    UIAlertView(基础版):

    1 UIAlertView *WXinstall=[[UIAlertView alloc]initWithTitle:@"提示框" message:@"提示信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];//一般在if判断中加入
    2 [WXinstall show];
     1 //监听点击事件 代理方法
     2 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
     3 {
     4     NSString *btnTitle = [alertView buttonTitleAtIndex:buttonIndex];
     5     if ([btnTitle isEqualToString:@"取消"]) {
     6          NSLog(@"你点击了取消");
     7     }else if ([btnTitle isEqualToString:@"确定"] ) {
     8          NSLog(@"你点击了确定");
     9         NSString *str = [NSString stringWithFormat:
    10                          @"https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8"];11         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    12 }//https在iTunes中找,这里的事件是前往手机端App store下载微信
    13 }

    UIAlertController(基础版):

     UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示信息" preferredStyle:UIAlertControllerStyleAlert];//UIAlertControllerStyleAlert视图在中央
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    NSString *str = [NSString stringWithFormat:
    @"https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];//https在iTunes中找,这里的事件是前往手机端App store下载微信
    [alertController addAction:cancelAction];

    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];

    2.第二种没得选型。

    UIAlertView(基础版):

    1 UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:@"你确定要退出应用吗?" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    2 [alert show];

    3.第三种多选型。

    //UIAlertControllerStyleAlert在中央屏幕。

    //UIAlertControllerStyleActionSheet在屏幕底部。

    UIAlertView(基础版):iOS8都弃用这里就略。

    UIAlertController(基础版):

     UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];
     //UIAlertControllerStyleAlert在中央屏幕。
     //UIAlertControllerStyleActionSheet在屏幕底部。
             UIAlertAction *useCamera = [UIAlertAction actionWithTitle:@"使用相机拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                 NSLog(@"这里是要调用相机拍照功能");
             }];
             UIAlertAction *desAction = [UIAlertAction actionWithTitle:@"destructive" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                 NSLog(@"这里是要调用销毁功能");
             }];
             UIAlertAction *usePhoto = [UIAlertAction actionWithTitle:@"使用相册照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                 NSLog(@"这里是要调用相册功能");
             }];
             UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
             [alertController addAction:useCamera];
             [alertController addAction:desAction];
             [alertController addAction:usePhoto];
             [alertController addAction:cancelAction];
             [self presentViewController:alertController animated:YES completion:nil];

    如果手机没有安装微信客户端的情况下,不要提示用户去安装,因为可能遇到审核的人不小心把你的应用拒了。

    UIAlertViewUIActionSheet在iOS8已经过期了,你仍然可以继续使用。UIAlertController这个接口类是一个定义上的提升,它添加简单,展示Alert和ActionSheet使用统一的API。因为UIAlertController使UIViewController的子类,他的API使用起来也会比较熟悉!

    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"选择睡前时间(分钟)" message:nil preferredStyle:UIAlertControllerStyleAlert];
            NSArray *timeArr = @[@"5",@"10",@"15",@"20",@"30",@"60"];
            NSInteger timeCount = [timeArr count];
            for (int i=0; i<timeCount; i++) {
                [alertVC addAction:[UIAlertAction actionWithTitle:timeArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [sender setTitle:action.title forState:UIControlStateNormal];
                }]];
            }
            [self presentViewController:alertVC animated:YES completion:nil];
        

     

  • 相关阅读:
    Windows Phone开发(29):隔离存储C 转:http://blog.csdn.net/tcjiaan/article/details/7447469
    Windows Phone开发(25):启动器与选择器之WebBrowserTask 转:http://blog.csdn.net/tcjiaan/article/details/7404770
    内存知识集
    牛人榜
    如何解决SQL Server 2000 中的连接问题(邹建)
    索引
    .net事件机制
    内核对象
    使用socket tcp实现通讯
    sql技巧
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/5976020.html
Copyright © 2011-2022 走看看