UITextView: текст начинается со 2-й строки текстового представления

У меня странная проблема. У меня есть 3 UITextField и один UITextView .Я могу перейти от одного UITextField к следующему UITextField по:

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
    NSInteger nextTag = textField.tag + 1;
    //-- try to find next responde
    UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];

    if (nextResponder) 
    {
        //-- found next responce ,so set it
        [nextResponder becomeFirstResponder];
    }
    else
    {
        [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        //-- not found remove keyboard
        [textField resignFirstResponder];
        return YES;
    }   

    return YES;
}

Все работает нормально, пока не дойдет до UITexView , затем мой курсор переместится на 2-ю строку текстовое представление вместо 1-й строки текстового представления.

Текстовое представление взято из IB.

Код для текстового представления:

- (void) textViewDidBeginEditing:(UITextView *)textView
{
    optionalText.hidden = YES ;
    [scrollView setContentOffset:CGPointMake(0, textView.center.y-100) animated:YES];
}

- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{       
    // Any new character added is passed in as the "text" parameter
    if ([text isEqualToString:@"\n"])
    {
        // Be sure to test for equality using the "isEqualToString" message
        [textView resignFirstResponder];
        [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];

        // Return FALSE so that the final '\n' character doesn't get added      
        if ([[commentTxtView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0)
        {
            optionalText.hidden = NO ;
            NSLog(@"Text View is null");
            [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        }

        return FALSE;
    }

    return TRUE;
}

Это выглядит так:

enter image description here

В чем может быть проблема? Почему он не начинается с 1-й строки текстового представления?

10
задан admdrew 10 September 2014 в 18:28
поделиться