• UIAlertView笔记


    链接地址:http://www.cnblogs.com/scandy-yuan/archive/2013/03/11/2954194.html

    1. 最简单的用法

    复制代码
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" 
    
                                                      message:@"这是一个简单的警告框!" 
    
                                                      delegate:nil   
    
                                                      cancelButtonTitle:@"确定" 
    
                                                      otherButtonTitles:nil];  
    
    [alert show];  
    复制代码

    2. 为UIAlertView添加多个按钮

    复制代码
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" 
    
                                                      message:@"请选择一个按钮:" 
    
                                                      delegate:nil   
    
                                                      cancelButtonTitle:@"取消" 
    
                                                      otherButtonTitles:@"按钮一", 
                                                                              @"按钮二",
                                                                              @"按钮三", nil]
    [alert show];                      
    复制代码

     3. 如何判断用户点击的按钮

    UIAlertView有一个委托UIAlertViewDelegate ,继承该委托来实现点击事件

    复制代码
    头文件:
    
    @interface MyAlertViewViewController : UIViewController<UIAlertViewDelegate> {
    
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
    
    -(IBAction) buttonPressed;
    
    @end
    
    
    源文件:
    
    -(IBAction) buttonPressed
    
    {
    
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" 
    
                                                     message:@"请选择一个按钮:" 
    
                                                     delegate:self   
    
                                                     cancelButtonTitle:@"取消" 
    
                                                     otherButtonTitles:@"按钮一", @"按钮二", @"按钮三",nil];  
    
    [alert show];  
    
    }
    
     
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    
    {
    
    NSString* msg = [[NSString alloc] initWithFormat:@"您按下的第%d个按钮!",buttonIndex];
    
     
    
    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示"
    
                                                     message:msg
    
                                                     delegate:nil
    
                                                     cancelButtonTitle:@"确定"
    
                                                     otherButtonTitles:nil];
    
     
    
    [alert show];
    
    }
    复制代码

    点击“取消”,“按钮一”,“按钮二”,“按钮三”的索引buttonIndex分别是0,1,2,3

    4.修改提示框样式

    iOS5中UIAlertView新增了一个属性alertViewStyle,它的类型是UIAlertViewStyle,是一个枚举值:

    typedef enum {
        UIAlertViewStyleDefault = 0,
        UIAlertViewStyleSecureTextInput,
        UIAlertViewStylePlainTextInput,
        UIAlertViewStyleLoginAndPasswordInput
    } UIAlertViewStyle;

    alertViewStyle属性默认是UIAlertViewStyleDefault。我们可以把它设置为UIAlertViewStylePlainTextInput,那么AlertView就显示为这样:

    UIAlertViewStyleSecureTextInput显示为:

    UIAlertViewStyleLoginAndPasswordInput为:

    当然我们也可以通过创建UITextField来关联这里的输入框并设置键盘响应的样式

    复制代码
    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"CD-KEY" 
    
                                                     message:@"please enter cd-key:" 
    
                                                     delegate:self   
    
                                                     cancelButtonTitle:@"Cancel" 
    
                                                     otherButtonTitles:@"Ok",nil];  
    [alert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
    
    UITextField * text1 = [alert textFieldAtIndex:0];
    
    UITextField * text2 = [alert textFieldAtIndex:1];
    
    text1.keyboardType = UIKeyboardTypeNumberPad;
    
    text2.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    
    [alert show];
    复制代码

        

    UIAlertViewStyleSecureTextInput和UIAlertViewStylePlainTextInput可以通过textFieldIndex为0来获取输入框对象。

    UIAlertViewStyleLoginAndPasswordInput可以通过textFieldIndex为0和1分别获取用户名输入框对象和密码输入框对象。

    如果一件事情你觉得难的完不成,你可以把它分为若干步,并不断寻找合适的方法。最后你发现你会是个超人。不要给自己找麻烦,但遇到麻烦绝不怕,更不要退缩。 电工查找电路不通点的最快方法是:分段诊断排除,快速定位。你有什么启示吗? 求知若饥,虚心若愚。 当你对一个事情掌控不足的时候,你需要做的就是“梳理”,并制定相应的规章制度,并使资源各司其职。
  • 相关阅读:
    luogu P3128 [USACO15DEC]最大流Max Flow (树上差分)
    codeforces 600E . Lomsat gelral (线段树合并)
    bzoj 1483: [HNOI2009]梦幻布丁 (链表启发式合并)
    bzoj 1257: [CQOI2007]余数之和 (数学+分块)
    codevs 2606 约数和问题 (数学+分块)
    bzoj 2038: [2009国家集训队]小Z的袜子(hose) (莫队)
    bzoj 1086: [SCOI2005]王室联邦 (分块+dfs)
    bzoj 4542: [Hnoi2016]大数 (莫队)
    【NOIp模拟赛】Tourist Attractions
    【NOIp模拟赛】String Master
  • 原文地址:https://www.cnblogs.com/wvqusrtg/p/5165879.html
Copyright © 2020-2023  润新知