Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
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?
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; } }
This is how I would do:
ReplyDeleteTag 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;
}
}