3

I have 1 problem when i click button "Next" of keypard to move cursor from TextField to TextView

The first ,all is ok. But in the second , the cursor jump into the line second of textView and then every time i click Next from TextField, the cursor in TextView will down one line more.

4

2 回答 2

8

Well, the question seems to be an intresting one. In most of the cases, the cursor jump is from one TextField to another TextField. Here you need to jump the editing from one TextField to another TextView, so you can try this method:

First create outlets for your textView and TextField, in your viewcontroller.h, say

@property (strong, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) IBOutlet UITextField *textField;

and viewcontroller.m do this:

 -(BOOL) textFieldShouldReturn:(UITextField *)textField
   {      
        if(textField isFirstResponder)
        {
            [textField resignFirstResponder];
            [textView becomeFirstResponder];
        }
        return YES;
    }

EDIT : If the method don't work as expected, this will make the change: '

-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
    if(textField isFirstResponder)
    {
        [textField resignFirstResponder];
        [textview performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.0];
    }
    return YES;
}

(To be honest, I have no idea how this performSelector with 0 delay solved the issue, but the solution worked for the OP .Thanks Luong Anh for the comment.)

于 2013-05-16T09:22:50.413 回答
0

you only need to put [yourtextView becomeFirstResponder]; in your textFieldShouldReturn method.

于 2013-05-16T09:39:24.360 回答