我在每个UITableViewRow上都有两个UITextField,并且由于某些原因,当我在UIKeyboard上按回车键时,两个特定的UITextField都不会重新组合起来(光标不可见)。
我有一个正在使用的自定义UITableViewCell,如果愿意,可以向您显示此代码,但是我不认为这是问题所在,因为返回键可用于95%的UITableViewCells。所以我在想,也许这就是我如何处理UITextFields的委托方法?
这是我用于委托方法的代码。
-(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;
}
我不知道在哪里寻找或如何找到此错误,因为它看起来是如此随机,但每次都在相同的UITextField上发生。
我认为上面的代码可能是问题所在。但是,在记录了所有内容并调试了几个小时之后,我开始认为这是UITableViewCells中的UITextFields的错误。
是[[self.view viewWithTag:textField.tag+1] canBecomeFirstResponder] == YES
?
您还需UITextField
要先辞职,然后再将下一个设置为第一响应者
[textField resignFirstResponder];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句