0
我有一個簡單的tableView。如果我點擊標籤(左側),didSelectRowAtIndexPath會觸發。當我點擊右側(textField)時它不會觸發。UITableView - didSelectRowAtIndexPath只在點擊標籤時觸發
我想不通,我錯過了什麼。我的代碼來創建和選擇單元格如下:
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);
}
所有幫助表示讚賞。
嗨John John試圖幫助我。但selectRowAtIndexPath不允許我標識該行。我已經在textFieldShould和textFieldDidBeginEditing中嘗試過了。構建自定義單元格的過程如何? –
看到我的第一個編輯。這是否回答你的問題? –
約翰,謝謝 - 我記錄cellContainingFirstResponder但它返回NULL。 –