• UI第十四节——UIAlertController


    - (void)viewDidLoad {
        [super viewDidLoad];
        
        UIButton *alertBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        alertBtn.frame = CGRectMake(40, 100, 295, 30);
        [alertBtn setTitle:@"Show AlertController" forState:UIControlStateNormal];
        [alertBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:alertBtn];
    }

    - (void)btnClicked:(UIButton *)btn
    {
        // UIAlertControllerStyleActionSheet ActionSheet的样式
        // UIAlertControllerStyleAlert       AlertView的样式
        
        //  实例化UIAlertController,这个东西是iOS8才有的
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"这是一个AlertController" message:@"这里是提示的内容" preferredStyle:UIAlertControllerStyleActionSheet];
        
        // 创建3个按钮
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"按钮1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
            NSLog(@"点击了按钮1");
        }];
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消按钮" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            
            NSLog(@"点击了取消按钮");
        }];
        
        UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"删除按钮" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            
            NSLog(@"点击了删除按钮");
        }];
        
        // 把按钮添加到AlertController里面
        [alertController addAction:action1];
        [alertController addAction:cancelAction];
        [alertController addAction:deleteAction];
        
        // 显示AlertController,用模式跳转的方式让其显示
        [self presentViewController:alertController animated:YES completion:^{
            
        }];
    }

    如果对你有帮助,请关注我哦!

  • 相关阅读:
    阿里云RDS的mysql数据库连接
    DRF框架400错误信息处理(视图集)
    关于百度Tongji Api的文档补充
    Python几种创建list的方法的效率对比
    手把手教你使用python复杂一点点的装饰器
    Python爬虫常用模块,BeautifulSoup笔记
    LSSS 构造过程
    微信网站应用扫码登陆
    分享一个自用的 Inno Setup 软件打包脚本
    彻底解决:请求被中止: 未能创建 SSL/TLS 安全通道
  • 原文地址:https://www.cnblogs.com/laolitou-ping/p/6244186.html
Copyright © 2020-2023  润新知