Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in iOS app, why does prepareForSegue occur before didSelectRowAtIndexPath

Tags:

iphone

ios5

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.

like image 977
JJW Avatar asked Apr 29 '12 23:04

JJW


2 Answers

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:.

like image 154
danh Avatar answered Nov 16 '22 18:11

danh


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]
like image 6
swampf0etus Avatar answered Nov 16 '22 17:11

swampf0etus