Monday, February 27, 2012

xcode 4 - custom keyboard with two Text Fields


I have created a custom keyboard and I have two text fields. When the user clicks on one of them, the keyboard appears.



How can I know which text field is currently active so that I write what the user is typing from the keyboard?

1 comment:

  1. This is how I would do:

    Tag both textfields (or use properties)

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


    Also set their delegates.

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


    On the .h file declare your class will implement the UITextFieldDelegate Protocol

    and on the .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;
    }
    }

    ReplyDelete