gpt4 book ai didi

ios - UITextField becomeFirstResponder 不显示文本光标

转载 作者:行者123 更新时间:2023-11-29 10:49:53 24 4
gpt4 key购买 nike

我在每个 UITableViewRow 上都有两个 UITextFields,由于某种原因,当我在 UIKeyboard 上按下回车键时,一个特定的行两个 UITextFields 都不会响应(光标不可见)。

我有一个正在使用的自定义 UITableViewCell,如果您愿意,我可以向您展示它的代码,但我认为这不是问题,因为返回键适用于 95% 的 UITableViewCell。所以我在想,也许这就是我处理 UITextFields 的委托(delegate)方法的方式?

这是我用于委托(delegate)方法的代码。

-(BOOL)textFieldShouldBeginEditing:(UITextField*)textfield {

int height = self.finishingTableView.frame.size.height;
self.finishingTableView.frame= CGRectMake(self.finishingTableView.frame.origin.x, self.finishingTableView.frame.origin.y, self.finishingTableView.frame.size.width, 307);

// select correct row
if (textfield.tag > 999999) {
int adjustTag = textfield.tag-1000000; // remove a million so that you have the text fields correct position in the table. (this is only for height textfields)
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:adjustTag inSection:0];
[finishingTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self tableView:finishingTableView didSelectRowAtIndexPath:indexPath];
[self.finishingTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
return YES;
} else {
NSIndexPath *indexPath =[NSIndexPath indexPathForRow:textfield.tag inSection:0];
[finishingTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self tableView:finishingTableView didSelectRowAtIndexPath:indexPath];
[self.finishingTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
return YES;
}
return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSLog(@"%i", textField.tag+1);

[[self.view viewWithTag:textField.tag+1] becomeFirstResponder];
// this means there has been a change in the UItextfield


NSLog(@"%@", selectedItemDictionary);
if (textField.tag < 999999) {
tempFinishingObjectDictionary = [selectedItemDictionary mutableCopy];
if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"mMM"]]) {
tempUpdatedRow = @"T";
// remove kevalues
[tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"];
[tempFinishingObjectDictionary removeObjectForKey:@"new_mMM"];
// update keyvalues
[tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"];
[tempFinishingObjectDictionary setValue:textField.text forKey:@"new_mMM"];
}
} else {
if (![textField.text isEqualToString:[selectedItemDictionary objectForKey:@"hMM"]]) {
tempUpdatedRow = @"T";
// remove kevalues
[tempFinishingObjectDictionary removeObjectForKey:@"updatedRow"];
[tempFinishingObjectDictionary removeObjectForKey:@"new_hMM"];
// update keyvalues
[tempFinishingObjectDictionary setValue:tempUpdatedRow forKey:@"updatedRow"];
[tempFinishingObjectDictionary setValue:textField.text forKey:@"new_hMM"];
}
}
NSLog(@"%@", tempFinishingObjectDictionary);
[coreDataController editSelectedFinishing:htmlProjID UpdatedNSD:tempFinishingObjectDictionary SelectedRow:selectedItemIndexPathRow];
[SVProgressHUD dismiss];


NSLog(@"%@", selectedItemDictionary);

return YES;
}

我不知道在哪里查看或如何找到这个错误,因为它看起来很随机,但每次都会在相同的 UITextFields 上发生。

上面的代码是我认为可能存在问题的地方;然而,在记录了所有内容并调试了几个小时后,我开始认为这是 UITableViewCells 中 UITextFields 的错误。

最佳答案

[[self.view viewWithTag:textField.tag+1] canBecomeFirstResponder] == YES?

在将下一个设置为第一响应者之前,您还需要退出当前的 UITextField

[textField resignFirstResponder];

关于ios - UITextField becomeFirstResponder 不显示文本光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20916133/

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