• UIAlertController警告视图和操作表单


     1 //创建一个myAlert1操作表单对象(UIAlertControllerStyleActionSheet为操作表单,UIAlertControllerStyleAlert为警告视图) 
     2   UIAlertController *myAlert1 = [UIAlertController alertControllerWithTitle:@"Are you sure?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     3     //创建一个操作表中的按钮对象(警告框、操作表默认没有按钮)
     4     //参数handler参数是个块,具体实现点击这个按钮所需处理的内容
     5     UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){
     6         
     7         NSString *msg;
     8         if ([self.nameText.text length] > 0) {
     9             msg = [NSString stringWithFormat:@"Your name is %@",self.nameText.text];
    10     
    11         }else{
    12             msg = @"You haven't input";
    13         }
    14         
    15         UIAlertController *myAlert2 = [UIAlertController alertControllerWithTitle:@"Something Was Done" message:msg preferredStyle:UIAlertControllerStyleAlert];
    16         
    17         UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Phew!" style:UIAlertActionStyleCancel handler:nil];
    18     //往myAlert2警告框对象中添加这个cancel按钮
    19         [myAlert2 addAction:cancelAction];
    20     //在屏幕中绘制警告框对话框
    21         [self presentViewController:myAlert2 animated:YES completion:nil];
    22     }];
    23     UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"No way!" style:UIAlertActionStyleCancel handler:nil];
    24     
    25     [myAlert1 addAction:yesAction];
    26     [myAlert1 addAction:noAction];
    27     
    28     //------这段代码开发iPhone app时可不写,iPad必须要写-------
    29     UIPopoverPresentationController *ppc = myAlert1.popoverPresentationController;
    30     
    31     if (ppc != nil) {
    32         ppc.sourceView = sender;
    33         ppc.sourceRect = sender.bounds;
    34         //设置iPad操作表单的属性,使箭头方向为往下指
    35         ppc.permittedArrowDirections = UIPopoverArrowDirectionDown;
    36     }
    37     //------这段代码开发iPhone app时可不写,iPad必须要写-------
    38     
    39     [self presentViewController:myAlert1 animated:YES completion:nil];
  • 相关阅读:
    Sqli Labs Less-21-31
    sqli labs Less-11-20
    基础知识补充及sqli-labs Less 5-10
    sqli-labs Less 2-4
    Sql简单的搜索语句及sqli-labs的less-1
    Sqli labs相关环境的下载与安装
    行内元素没有宽高,块级元素有宽高
    Webview上传文件的那些坑
    [Android开发] 代码code设置9.png/9-patch 图片背景后,此view中的TextView等控件显示不正常(常见于listview中)
    AndroidSupportDesign之TabLayout使用详解
  • 原文地址:https://www.cnblogs.com/MrHead/p/5753311.html
Copyright © 2020-2023  润新知