I have a simple tableView. If I tap on the label (left side), didSelectRowAtIndexPath fires ok. It does not fire when I tap on the right side (textField).
I cannot figure what I’m missing.. My code to create and select the cells is as follows:
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);
}
All help appreciated.
I’m pretty sure this is by design. Tapping inside a UITextField that is in a row doesn’t automatically select the row. If your rows have Accessory Buttons, tapping them doesn’t select the row, either.
Edit
If you’d like to know the index path of the TableViewCell that contains the active TextField, add this to your textFieldShould/DidBeginEditing: