• UIAlertView和UIAlertViewController


     1 #import "ViewController.h"
     2 
     3 @interface ViewController ()<UIAlertViewDelegate>
     4 
     5 @end
     6 
     7 @implementation ViewController
     8 
     9 - (void)viewDidLoad {
    10     [super viewDidLoad];
    11     // Do any additional setup after loading the view, typically from a nib.
    12 }
    13 - (IBAction)didClickButtonAction:(UIButton *)sender {
    14     
    15     //版本判断
    16     float version = [UIDevice currentDevice].systemVersion.floatValue;
    17     if (version < 8.0) {
    18         
    19         //iOS8.0以前UIAlertView,用show展示
    20             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"密码错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"孟德峰",@"原溢凯", nil];
    21             //弹出alertView
    22             [alertView show];
    23         
    24     }else{
    25         //iOS8.0以后UIAlertController,用模态展示
    26         UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"密码错误" preferredStyle:UIAlertControllerStyleActionSheet];
    27         //添加点击按钮
    28         [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    29             NSLog(@"点击确定");
    30         }]];
    31         [self presentViewController:alertC animated:YES completion:nil];
    32     }
    33     
    34 }
    35 //代理方法,判断点击了那个按钮
    36 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    37 {
    38     NSLog(@"%ld",buttonIndex);
    39 }
  • 相关阅读:
    03 重定向,请求转发,cookie,session
    02 http,servlet,servletconfig,HttpServletRequest ,HttpServletResponse
    02 JDBC相关
    01 mysql
    16 反射,枚举,新特性
    13 递归练习
    12 IO流
    11 异常
    兼容当前五大浏览器的渐变颜色背景gradient的写法
    Electron Browser加载iframe(webview src属性)
  • 原文地址:https://www.cnblogs.com/DevinSMR/p/5285050.html
Copyright © 2020-2023  润新知