Ios UITextField成为第一响应程序,不显示文本光标
我在每个UITableViewRow上都有两个UITextField,由于某种原因,当我在UIKeyboard上按return键时,两个UITextFields中的一个特定行都不会响应(光标不可见) 我有一个我正在使用的自定义UITableViewCell,如果您愿意,我可以向您展示此代码,但是我认为这不是问题所在,因为返回键适用于95%的UITableViewCell。所以我在想,也许是我如何处理UITextFields的委托方法 这是我用于委托方法的代码Ios UITextField成为第一响应程序,不显示文本光标,ios,uitableview,uitextfield,Ios,Uitableview,Uitextfield,我在每个UITableViewRow上都有两个UITextField,由于某种原因,当我在UIKeyboard上按return键时,两个UITextFields中的一个特定行都不会响应(光标不可见) 我有一个我正在使用的自定义UITableViewCell,如果您愿意,我可以向您展示此代码,但是我认为这不是问题所在,因为返回键适用于95%的UITableViewCell。所以我在想,也许是我如何处理UITextFields的委托方法 这是我用于委托方法的代码 -(BOOL)textFieldSh
-(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;
}
-(BOOL)textfield应该开始编辑:(UITextField*)textfield{
内部高度=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);
//选择正确的行
如果(textfield.tag>999999){
int adjustTag=textfield.tag-1000000;//删除一百万,使文本字段在表中的位置正确。(这仅适用于高度文本字段)
NSIndexPath*indexPath=[NSIndexPath indexPathForRow:adjustTag片段:0];
[finishingTableView SelectRowatingIndexPath:indexPath动画:无滚动位置:UITableView滚动位置无];
[self tableView:finishingTableView didSelectRowAtIndexPath:indexPath];
[self.finishingTableView ScrollToRowatinexPath:indexPath atScrollPosition:UITableViewScrollPositionNone动画:是];
返回YES;
}否则{
nsindepath*indepath=[nsindepath indexPathForRow:textfield.tag片段:0];
[finishingTableView SelectRowatingIndexPath:indexPath动画:无滚动位置:UITableView滚动位置无];
[self tableView:finishingTableView didSelectRowAtIndexPath:indexPath];
[self.finishingTableView ScrollToRowatinexPath:indexPath atScrollPosition:UITableViewScrollPositionNone动画:是];
返回YES;
}
返回YES;
}
-(BOOL)textField应返回:(UITextField*)textField
{
NSLog(@“%i”,textField.tag+1);
[[self.view-view-withtag:textField.tag+1]成为第一响应者];
//这意味着UItextfield发生了更改
NSLog(@“%@”,selectedItemDictionary);
如果(textField.tag<999999){
tempFinishingObjectDictionary=[selectedItemDictionary mutableCopy];
如果(![textField.text IsequalString:[selectedItemDictionary objectForKey:@“mMM”]]){
tempUpdatedRow=@“T”;
//删除kev值
[tempFinishingObjectDictionary removeObjectForKey:@“updatedRow”];
[tempFinishingObjectDictionary removeObjectForKey:@“new_mMM”];
//更新键值
[tempFinishingObjectDictionary设置值:tempUpdatedRow forKey:@“updatedRow”];
[tempFinishingObjectDictionary设置值:textField.text forKey:@“new_mMM”];
}
}否则{
if(![textField.text IsequalString:[selectedItemDictionary objectForKey:@“hMM”]]){
tempUpdatedRow=@“T”;
//删除kev值
[tempFinishingObjectDictionary removeObjectForKey:@“updatedRow”];
[tempFinishingObjectDictionary removeObjectForKey:@“new_-hMM”];
//更新键值
[tempFinishingObjectDictionary设置值:tempUpdatedRow forKey:@“updatedRow”];
[tempFinishingObjectDictionary设置值:textField.text forKey:@“new_hMM”];
}
}
NSLog(@“%@”,tempFinishingObjectDictionary);
[coreDataController editSelectedFinishing:htmlProjID UpdatedNSD:tempFinishingObjectDictionary SelectedRow:SelectedEditItemIndexPathRow];
[SVD解散];
NSLog(@“%@”,selectedItemDictionary);
返回YES;
}
我不知道在哪里查找或如何查找此错误,因为它看起来很随机,但每次都发生在相同的UITextFields上
上面的代码是我认为问题可能存在的地方;然而,在记录了所有内容并调试了几个小时之后,我开始认为这是UITableViewCells中UITextFields的一个缺陷。是
[[self.view viewWithTag:textField.tag+1]可以成为第一响应者]==是
在将下一个设置为第一个响应者之前,您还需要退出当前的UITextField
[textField resignFirstResponder];
我只是试着在我设置textfield.tag+1的地方添加resignFirstResponder。它从视图中删除了UIKeyboard,但仍然没有使textfield.tag+1成为第一响应者。如果这是结果,您可以检查/记录吗?[[self.view viewWithTag:textField.tag+1]可以成为第一响应者]==是的,我们正在尝试解决如何做到这一点,并将尽快通知您。。。只是不确定如何记录才能成为第一响应者类似于此NSLog的内容([[self.view viewWithTag:textField.tag+1]可以成为第一响应者]?@“是”:@“否”);是的,我知道怎么记录了。而UItextfield返回NO