zoukankan      html  css  js  c++  java
  • IOS学习笔记(四)AlertView

    【转】   

    alertView     有两个button时,一般默认使左边的是取消,右边的是确认。苹果习惯~

    alertView 的属性是可以设置的。   [AlertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];     <

    UIAlertView *alertView = [UIAlertView alloc] initWithTitle:@"DefaultAlertView"message:@"Defalut" 

                                          delegate:self cancelButtonTitle:@"Cancel" 

                                     otherButtonTitles:@"OK", nil];   <

    显示alertView            [alertView show];   <

    代理方法     

          按index索引点击事件,index从0开始          - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex                           这个方法在动画结束和视图隐藏之后调用  - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex                             这个方法在动画开始和视图隐藏之前调用      - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex                在视图将要被取消之前          - (void)alertViewCancel:(UIAlertView *)alertView                                      在视图提交给用户以后调用                       - (void)didPresentAlertView:(UIAlertView *)alertView                                              

               设置yes / no  将会设置alertView 的第一个otherButton的enable属性   - (BOOL)alertViewShouldEnableFirstOtherButton(UIAlertView *)alertView
        这六个delegate 方法调用的顺序依次是
        alertViewShouldEnableFirstOtherButton
        willPresentAlertView 
        didPresentAlertView 
        clickedButtonAtIndex 
        willDismissWithButtonIndex(如果会触发视图取消,则会调用alertViewCancel) 
        didDismissWithButtonIndex
     
    ios4.0以后 alertView不会自动随着程序转向后台而移除
    alertView属性
    1.alertViewStyle:
    只弹信息和按钮        UIAlertViewStyleDefault 
    有一个textfield加密框     UIAlertViewStyleSecureTextInput 
    有一个不加密的      textfieldUIAlertViewStylePlainTextInput 
    有两个textfield,     Login和passwordUIAlertViewStyleLoginAndPasswordInput  
    只要有textfield就可以用textfieldAtIndex来捕获并进行相应的操作例如换键盘类型
     
    2.cancelButtonIndex     开始是0,如果没有设置cancel button 则是-1 
    3.delegate        如果没有设置则是nil 
    4.firstOtherButtonIndex    从0开始,如果没设置则是-1,而且没被设置则会被忽略 
    5.message           消息 
    6.numberOfButtons          只读  alertView中的按钮数量 
    7.title           标题 
    8.visible         只读  如果是yes 表示被显示
     
    实例方法
    返回值是增加的Button的index              - (NSInteger)addButtonWithTitle:(NSString *)title 
    输入buttonIndex 返回button的标题      - (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex
    程序自动完成点击buttonIndex的button 并dismiss 整个alertView的操作   
                         - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
    要显示必须要调用这个alertview才会显示  - (void)show
     
    返回值是textfield          -  (UITextField *)textfieldAtIndex:(NSInteger)textfieldIndex
    UIAlertViewStyleDefault 没有
    UIAlertViewStyleSecureInput textfieldIndex 只有一个为0
    UIAlertViewStylePlainInput textfieldIndex 只有一个为0
    UIAlertViewStyleLoginAndPasswordInput textfieldIndex有两个 0 1
  • 相关阅读:
    使用tcmalloc编译启动时宕机
    使用tcmalloc编译出现undefined reference to `sem_init'
    使用AddressSanitizer做内存分析(一)——入门篇
    VIM-美化你的标签栏
    Entity Framework Code First (六)存储过程
    Entity Framework Code First (五)Fluent API
    Entity Framework Code First (四)Fluent API
    Entity Framework Code First (三)Data Annotations
    Entity Framework Code First (二)Custom Conventions
    Entity Framework Code First (一)Conventions
  • 原文地址:https://www.cnblogs.com/fsliu/p/4241424.html
Copyright © 2011-2022 走看看