Reputation:
I can't get the return key in my UITextField's
to work!
I have quite a lot of UITextField's
so can someone give a short bit of code?
Upvotes: 1
Views: 1375
Reputation: 7931
If you have a lot of text fields and you want the return key to bring up the next textfield. So the user can enter data quickly. Then set the set the delegate for each textfield to be your view controller with
textField.delegate = self;
make sure your view controller adopts the UITextFieldDelegate protocol by putting this in the interface declaration
<UITextFieldDelegate>
then use the textFieldShouldReturn method
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.Field1) {
[self.Field2 becomeFirstResponder];
}
else if (textField == self.Field2) {
[self.Field3 becomeFirstResponder];
}
else if (textField == self.Field3) {
[self.Field4 becomeFirstResponder];
}
else if (textField == self.Field4) {
[self.Field5 becomeFirstResponder];
}
else if (textField == self.Field5) {
[self.Field5 resignFirstResponder];
}
return YES;
}
Upvotes: 1
Reputation: 8109
check that the textField.delegate = self;
where self is current UIViewController
is set and then check if you are resigning the textfield by: [textField resignFirstResponder];
Upvotes: 0
Reputation: 3000
Try this
- (IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}
You will have to connect this to all the text fields you have. Use the Did End On Exit
option when connecting to the File's Owner
.
Upvotes: 0