Search code examples
iosxcodeuipopovercontroller

get index path for editing row in prepareForSegue?


I am presenting a popover from a UITableView and using the prepareForSegue method as discussed in In WWDC 2014 "View Controller Advancements in iOS8"

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

UINavigationController * nvc = segue.destinationViewController;
UIPopoverPresentationController * pvc = nvc.popoverPresentationController;
pvc.delegate = self;
}

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return UIModalPresentationNone;
}

Problem is, I need to pass a value from the edited row to the popover. Is there a way to do this cleanly such as (I know it doesn't exist, but)

[self.myTableView indexPathForEditingRow];

I tried

[self.myTableView indexPathForSelectedRow];

but this returns the first row in the table.


Solution

  • Check, who your sender is. If it is a cell, you have all you need. If not, you need to make a property and remember the index path in didSelectCell method of the tableView delegate.