按下Return键时从UITextField移至UITextView [英] Move From UITextField to UITextView When Return Pressed

查看:160
本文介绍了按下Return键时从UITextField移至UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有几个文本视图.除了一个是UITextField,其他都是UITextView,位于另一个的中间.这是因为此部分需要更多空间供用户键入并查看他们正在键入的所有内容.我进行了设置,以便在用户按下键盘上的next键时,使用以下代码转到下一个字段:

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;
}

一切正常,直到我进入UITextView.当我单击下一步时,它只是将光标下移了一行.我如何获得响应以简单地转到下一个字段?

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?

推荐答案

您可以尝试两种方法:

1)使用功能

-(BOOL)textViewShouldReturn:(UITextView *)textView

实现所需的行为.

2)阅读:

如何关闭带有返回键的UITextView键盘?/a>

How to dismiss keyboard for UITextView with return key?

并使这些解决方案适应您的需求.

and adapt those solutions to your neeeds.

这篇关于按下Return键时从UITextField移至UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆