0

私は単純な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);
}

すべての助けに感謝します。

4

1 に答える 1

2

これは設計によるものだと確信しています。行にある UITextField 内をタップしても、行は自動的に選択されません。行にアクセサリ ボタンがある場合、それらをタップしても行は選択されません。

編集

アクティブな TextField を含む TableViewCell のインデックス パスを知りたい場合は、これを textFieldShould/DidBeginEditing に追加します。

id cellContainingFirstResponder = textField.superview.superview ;
NSIndexPath* indexPathContainingFirstResponder = [self.tableView indexPathForCell:cellContainingFirstResponder] ;
于 2013-02-04T22:59:08.450 に答える