I have a grouped table view that contains 3 sections and each row per section. The first two section rows contains UITextField(Name & Subject are the section titles) and the last one contains UITextView(Message is the section title) because i want to get some data from the user by this controller itself.
The two text fields have the returnKeyType as UIReturnKeyNext. For UITextView, the "return" button is present in keyboard to feed new line. So i used textFieldShouldReturn method to navigate to the next cell by pressing these return type buttons in UIKeyboard.
The next button will work fine with the first text field(Name). Here the problem comes... If i click the Next button of second cell, It goes to the UITextView(last cell) with one line down. That is, the cursor moves one line apart from its original position.
My code is...
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
if (textField == nameTextField) {
[subjectTextField becomeFirstResponder];
}
else if(textField == subjectTextField) {
[messageTextView becomeFirstResponder];
}
return YES;
}
What should i do to make this work fine? Thanks in Advance..
While testing a lot of stuff I found a simple yet suitable solution:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ( [textField isEqual: nameTextField] )
{
[nameTextField resignFirstResponder];
[messageTextView becomeFirstResponder];
return NO;
}
return YES;
}
It handles the resigning of the nameTextField itself and returns NO to the request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With