Alex Rivera | Logout

in iOS app, why does prepareForSegue occur before didSelectRowAtIndexPath

Asked 2012-04-29T23:38:43.073
13

I'm trying to change the cell behavior to: 1) When Cell Tapped, Mark Cell as Complete with a check mark 2) When Detail Disclosure Accessory button is tapped, perform the Segue. 3) In tableView:didSelectRowAtIndexPath: I have:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    AWDelivery *delivery = [self.fetchedResultsController objectAtIndexPath:indexPath];
    [delivery toggleDelivered: delivery];
    [self configureCheckmarkForCell:cell withDelivery:delivery];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (debugging) NSLog(@"[%s] [%d]", __PRETTY_FUNCTION__, __LINE__);
}

the deselectRowAtIndexPath is supposed to bypass the segue, but it's not.

NSLogs: a) at 2012-04-29 18:50:00.848 Delivery[3148:fb03] [-[DeliveryTVC prepareForSegue:sender:]] [168] b) at 2012-04-29 18:50:01.245 Delivery[3148:fb03] [-[DeliveryTVC tableView:didSelectRowAtIndexPath:]] [93]

note that 'didSelect' occurs after 'prepareForSegue'.

Any hints would be most appreciated.

Edit
Report

2 Answers

14

Do you have your detail segue attached to the table view cell? Instead, try dragging it between the two view controllers (the one containing the table and the one where you want it to go).

Then perform it manually ([self performSegueWithIdentifier:@"MySegue"];) when tableView:accessoryButtonTappedForRowWithIndexPath:.

answered 2012-04-30T00:04:37.140
6

If you need to get the current tableview selection in prepareForSegue you can get it by accessing the UITableViewController's tableView ivar;

[self tableView] indexPathForSelectedRow]
answered 2012-07-02T18:01:26.137

Your Answer