我有一个 UITableView,它有 2 个不同的 customcell 定义。一个是单个 UITextField,另一个是 4 个 UITextField
userInteractionEnabled 手动设置为启用单元格级触摸导航,并且我在 didSelectRowAtIndexPath 中处理 UI 交互到相关单元格的第一响应者
当我只使用一个自定义单元格 (EditableCustomCell) 和一个 UITextField (editableTextField) 时,这一切都很好,但现在我有一个自定义单元格 (LatLonCustomCell) 和 4 个 UITextFields(度、分、秒、笛卡尔),我无法确定哪个字段有被触摸以设置 becomeFirstResponder
(目前我在调试期间默认使用第一个名为 degree 的文本字段)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[prevField resignFirstResponder];
prevField.userInteractionEnabled = NO;
if(indexPath.section == kFirstSection && (indexPath.row == kLatitudeRow || indexPath.row == kLongitudeRow)) {
LatLonCustomCell *customCell = (LatLonCustomCell *)[MyTableView cellForRowAtIndexPath:indexPath];
currField = customCell.degrees; // need to set correct field here
} else {
EditableCustomCell *customCell = (EditableCustomCell *)[MyTableView cellForRowAtIndexPath:indexPath];
currField = customCell.editableTextField;
}
currFieldIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
currField.userInteractionEnabled = YES;
[currField becomeFirstResponder];
}