【问题标题】:xcode 4 - custom keyboard with two Text Fieldsxcode 4 - 带有两个文本字段的自定义键盘
【发布时间】:2012-03-16 05:56:05
【问题描述】:

我创建了一个自定义键盘,并且有两个文本字段。当用户点击其中一个时,就会出现键盘。

我如何知道哪个文本字段当前处于活动状态,以便我写下用户从键盘输入的内容?

【问题讨论】:

    标签: iphone xcode keyboard xcode4.2 textfield


    【解决方案1】:

    我会这样做:

    标记两个文本字段(或使用属性)

    textField1.tag = 100;
    textField2.tag = 101;
    

    同时设置他们的代表。

    textField1.delegate = self;
    textField2.delegate = self;
    

    在 .h 文件中声明你的类将实现 UITextFieldDelegate 协议

    在.m上

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        if (textField.tag == 100) //you should use a constant instead of 100
        {
            //set a breakpoint here so you would know your typing the first textField
            return YES;
        }
    }
    

    【讨论】:

    • 你的意思是:在 .h 文件中声明你的类将实现 UITextFieldDelegate 协议
    • @interface YourViewController : UIViewController
    猜你喜欢
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多