Move from UITextField to UITextView when the return is pressed

I have several text views in my app. All but one are UITextField, and the other is a UITextView, located right in the middle of the others. This is due to this section needing much more room for the user to type and see all of what they are typing out. I have it set up so that when the user presses next on the keyboard, it goes to the next field, using this code:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == firstName) {
        [firstName resignFirstResponder];
        [lastName becomeFirstResponder];
    } else if (textField == lastName) {
        [lastName resignFirstResponder];
        [theRequest becomeFirstResponder];
    }
    else if (textField == theRequest) {
        [theRequest resignFirstResponder];
        [theDetails becomeFirstResponder];
    }
    else if (textField == theDetails) {
        [theDetails resignFirstResponder];
        [textdate becomeFirstResponder];
    }
    else if (textField == textdate) {
        [textdate resignFirstResponder];
        [location becomeFirstResponder];
    }
    else if (textField == location) {
        [location resignFirstResponder];

    }
    return YES;
}

Everything goes fine until I get to the UITextView. When I click next there, it simply pushes the cursor down a line. How can I get it to respond to simply go to the next field?

Also, when clicking Next in location, it goes back to first name. How can that be setup to just dismiss keyboard?

You can try two ways:

1) Use function

-(BOOL)textViewShouldReturn:(UITextView *)textView

to realize needed behaviour.

2) Read this:

How to dismiss keyboard for UITextView with return key?

and adapt those solutions to your neeeds.

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Move from UITextField to UITextView when the return is pressed

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录