• 警告视图例子:请求用户的文本输入


    这里有涉及到这么一段代码:
    @interface UIAlertView (extended)
    - (UITextField *) textFieldAtIndex: (int) index;
    - (void) addTextFieldWithValue: (NSString *) value label: (NSString *) label;
    @end


    前面有一篇blog也涉及到(extended),没有理解到具体。

    这里解答下:
    先以上述代码来说,假定UIAlertView的头文件和实现文件分别是UIAlertView.h和UIAlertView.m(之所以假定,因为你只找到UIAlertView.h文件,找不到UIAlertView.m文件,这个实现文件肯定被编译,不会公开的)

    代码中的方法textFieldAtIndex和addTextFieldWithValue,在头文件找不到,而在实现文件中。至于是不是Category实现就不可而知。

    这里需要把隐藏的方法声明一下

    好了,回到正题来,后续代码很简单,看下:
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
    printf(
    "User Pressed Button %d\n", buttonIndex + 1);
    printf(
    "Text Field 1: %s\n", [[[alertView textFieldAtIndex:0] text] cStringUsingEncoding:1]);
    printf(
    "Text Field 2: %s\n", [[[alertView textFieldAtIndex:1] text] cStringUsingEncoding:1]);
    [alertView release];
    }

    - (void) presentSheet
    {
    UIAlertView
    *alert = [[UIAlertView alloc]
    initWithTitle:
    @"Enter Information"
    message:
    @"Specify the Name and URL"
    delegate:self
    cancelButtonTitle:
    @"Cancel"
    otherButtonTitles:
    @"OK", nil];
    [alert addTextFieldWithValue:
    @"" label:@"Enter Name"];
    [alert addTextFieldWithValue:
    @"http://" label:@"Enter URL"];

    // Name field
    UITextField *tf = [alert textFieldAtIndex:0];
    tf.clearButtonMode
    = UITextFieldViewModeWhileEditing;
    tf.keyboardType
    = UIKeyboardTypeAlphabet;
    tf.keyboardAppearance
    = UIKeyboardAppearanceAlert;
    tf.autocapitalizationType
    = UITextAutocapitalizationTypeWords;
    tf.autocorrectionType
    = UITextAutocorrectionTypeNo;

    // URL field
    tf = [alert textFieldAtIndex:1];
    tf.clearButtonMode
    = UITextFieldViewModeWhileEditing;
    tf.keyboardType
    = UIKeyboardTypeURL;
    tf.keyboardAppearance
    = UIKeyboardAppearanceAlert;
    tf.autocapitalizationType
    = UITextAutocapitalizationTypeNone;
    tf.autocorrectionType
    = UITextAutocorrectionTypeNo;

    [alert show];
    }


    loadView中绑定presentSheet方法

    如果按照SDK公开的方法来做的话,肯定想其它方式来处理。晓得了,需要搜集有用的非公开函数,以备用开发。


    无论生活、还是技术,一切都不断的学习和更新~~~努力~
  • 相关阅读:
    Spring-----aop
    Activity的四种launchMode《转》
    解决gradle /Users/xxxx/Documents/workspace/fontmanager/.gradle/2.2.1/taskArtifacts/cache.properties (No such file or directory)报错办法
    Mac删除JDK
    Mac OSX Java 编译时乱码问题
    android中出现Error retrieving parent for item: No resource found that matches the Theme.AppCompat.Light
    使用AndroidStudio报错:INSTALL_FAILED_UPDATE_INCOMPATIBLE
    Java 类库和常用类库
    (斐波那契总结)Write a method to generate the nth Fibonacci number (CC150 8.1)
    各种排序学习归纳总结(Java)
  • 原文地址:https://www.cnblogs.com/GoGoagg/p/2056676.html
Copyright © 2020-2023  润新知