UITableView - didSelectRowAtIndexPath仅在点击标签时触发

时间:2013-02-04 22:34:17

标签: uitableview ios6

我有一个简单的tableView。如果我点击标签(左侧),didSelectRowAtIndexPath会触发。当我点击右侧(textField)时它不会触发。

我无法想象我错过了什么..我创建和选择单元格的代码如下:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];

        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
        textField.delegate = self;
        textField.returnKeyType = UIReturnKeyDone;
        textField.borderStyle = UITextBorderStyleNone;
        cell.accessoryView = textField;
        textField.text = [NSString stringWithFormat:@"%d ", indexPath.row];
    }

    cell.textLabel.text = [NSString stringWithFormat:@"Line %d", indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s", __FUNCTION__);
    currentIndexPath = indexPath;
    NSLog(@"didSelect currentIndexPath.section is %i", currentIndexPath.section);
    NSLog(@"didSelect currentIndexPath.row is %i", currentIndexPath.row);
}

所有帮助表示赞赏。

1 个答案:

答案 0 :(得分:2)

我很确定这是设计的。点击连续的UITextField内部不会自动选择该行。如果您的行包含附件按钮tapping them doesn't select the row, either.

修改

如果您想知道包含活动TextField的TableViewCell的索引路径,请将其添加到textFieldShould / DidBeginEditing:

id cellContainingFirstResponder = textField.superview.superview ;
NSIndexPath* indexPathContainingFirstResponder = [self.tableView indexPathForCell:cellContainingFirstResponder] ;