gpt4 book ai didi

iphone - UITextView : Text starts from 2nd line of text view

转载 作者:行者123 更新时间:2023-12-03 18:29:26 25 4
gpt4 key购买 nike

我有一个奇怪的问题。我有 3 个 UITextField 和 1 个 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,然后我的光标移动到 TextView 的第二行,而不是 TextView 的第一行。

TextView 取自IB。

TextView 的代码:

- (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

可能是什么问题?为什么它不从 TextView 的第一行开始?

最佳答案

我敢打赌,如果 nextResponder 是您的 UITextField,您的 textFieldShouldReturn: 应该返回 NO。现在您总是返回 YES,这意味着 key 可能会传递给 UITextView,然后插入新行。

关于iphone - UITextView : Text starts from 2nd line of text view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8037679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com