zoukankan      html  css  js  c++  java
  • 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];
  • 相关阅读:
    html <a> 标记 颜色与下划线 muddy
    sharepoint 获得当前登录人的用户名(转载) muddy
    AspNetPager+GridView分页实现
    UpdatePanel的简单用法(1)
    LINQ to SQL系列三 使用DeferredLoadingEnabled,DataLoadOption指定加载选项
    Custom Sharepoint Lookup Field
    Gridview使用LINQ分页例子
    合并GridView中某行相同信息的行
    初学LINQ增删改查(一)
    ASP.NET购物车
  • 原文地址:https://www.cnblogs.com/MrHead/p/5753311.html
Copyright © 2011-2022 走看看