zoukankan      html  css  js  c++  java
  • 警告视图例子:请求用户的文本输入

    这里有涉及到这么一段代码:
    @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公开的方法来做的话,肯定想其它方式来处理。晓得了,需要搜集有用的非公开函数,以备用开发。


    无论生活、还是技术,一切都不断的学习和更新~~~努力~
  • 相关阅读:
    php json_encode怪问题
    给phpcms v9添加热门搜索关键词
    magento 1.6 后台无法登录解决办法
    08 baidu QA
    java exception
    java thread / process / thread runnable / thread sleep / thread run
    java reflect
    db sysbase
    内存单元
    分段的方式来管理内存
  • 原文地址:https://www.cnblogs.com/GoGoagg/p/2056676.html
Copyright © 2011-2022 走看看