I have a PrototypeCell with two buttons in it each button will segue to an other detailed view of the displayed item. When I touch a button in the cell, I set a NSNumber
to the selected buttons index (1 or 2) and set the cell selected. The cell then changes its color to grey (highlighted), but the UITableViews
delegate method didSelectRowAtIndexPath
does not get called.
How do I do it the right way? Cant figure it out.
Here's my code so far:
Inside the UITableViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
TwoButtonPrototypeCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setupButtons];
NSArray *array1 = [entries objectAtIndex:indexPath.row * 2];
NSArray *array2 = [entries objectAtIndex:indexPath.row * 2 + 1];
cell.identifier1 = [array1 objectAtIndex:0];
cell.identifier2 = [array2 objectAtIndex:0];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TwoButtonPrototypeCell *cell = (TwoButtonPrototypeCell *)[tableView cellForRowAtIndexPath:indexPath];
identifier = cell.touchedButtonIdentifier;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSegueWithIdentifier:@"showDetails" sender:self];
}
Inside the TwoButtonPrototypeCell
- (void)setupButtons {
[button1 addTarget:self action:@selector(touchedButton1) forControlEvents:UIControlEventTouchUpInside];
[button2 addTarget:self action:@selector(touchedButton2) forControlEvents:UIControlEventTouchUpInside];
}
- (void)touchedButton1 {
touchedButtonIdentifier = identifier1;
[self setSelected:YES animated:NO];
}
- (void)touchedButton2 {
touchedButtonIdentifier = identifier2;
[self setSelected:YES animated:NO];
}