Reputation: 85
I am facing a problem in shifting the focus to next textfield in Ipad.
Scenario :
[TEXTFIELD1] [TEXTFIELD2]
When enter pressed on TEXTFIELD1 shift the focus to TEXTFIELD2.
I have googled the workarounds and tried them but nothing works.
Please help me on this.
Upvotes: 0
Views: 173
Reputation: 4143
Easiest way to do is to set the tag property of your textfields then
- (void)textFieldShouldReturn:(UITextField *)textField {
UITextField *nextField = (UITextField*)[self.view viewWithTag:textField.tag + 1];
// if a textfield with this tag exist make it first responder
if(nextField)
{
[nextField becomeFirstResponder];
}
else
{
// hide keyboard
[self.view endEditing:YES];
}
return YES;
}
Upvotes: 1
Reputation: 1300
You should make 2 IBOutlets to your textFields and for both of them set the delegate.
You have to implement this method in the delegate:
- (void)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.textField1) {
[self.textField2 becomeFirstResponder];
}
return YES;
}
Now, when the user presses return in textField1, textField2 will be focused.
Upvotes: 0