1
votes

I have been sourcing for codes/tutorials on iPhone UITextField. I came across its sample code on how to use API commands for it. I then created my TextFields programmatically, and now I cant close the keyboard when I press Done. I know the command is resignFirstResponder. But when and how do I use it?

Here is what I did.

textField = [[UITextField alloc] initWithFrame:CGRectMake(yView, xView, 100, 25)];

textField.borderStyle = UITextBorderStyleRoundedRect;

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

textField.returnKeyType = UIReturnKeyDone;

[textField setText:(@"test")];

[self addSubview:textField];

Now, where do I put the resignFirstResponder? The sample code did it by using a viewController. I did mine in a view. I hope it is possible to be done on a view.

Thanks.

1

1 Answers

2
votes

Add a delegate to the textfield, and use the delegate call textFieldShouldReturn:

Here is the apple documentation