2

This will probably take two seconds to answer, but my search skills have not gotten me very far on this issue. I am performing a segue but I'm not sure how to grab the id on the destination. Here is my code on the tableview controller.

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath: NSIndexPath *)indexPath{
    NSLog(@"reaching accessoryButtonTappedForRowWithIndexPath:");
    [self performSegueWithIdentifier:@"leads_calls_to_detail" sender:[[self.leads_calls objectAtIndex:indexPath.row] objectForKey:@"ID"]];
}

What do I have to create on my destination view controller to be able to grab the id that I'm attempting to pass, or is the way I'm performing my segue incompatible with what I am attempting?

BryanH
  • 5,826
  • 3
  • 34
  • 47
Chris Jenkins
  • 719
  • 7
  • 20
  • 1
    You need to implement a [`prepareForSegue`](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/prepareForSegue:sender:), in which you can refer to `segue.destinationController`. – Rob Jun 11 '13 at 17:23

1 Answers1

7

You should just pass values to the destinationViewController inside prepareForSegue: and pass self as the sender.. try using something like:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"leads_calls_to_detail"])
    {
       YourViewController *controller=(YourViewController *)segue.destinationViewController;
       NSIndexPath *path = [self.tableView indexPathForSelectedRow];
      //Or rather just save the indexPath in a property in your currentViewController when you get the accessoryButtonTappedForRowAtIndexPath callback, and use it here
       controller.yourPropertyToSet = [self.leads_calls objectAtIndex:path.row];
    }
}

And also according to Rob Mayoff, you can grab the index path for the row that the accessory was tapped at by using something like this:

NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];//where sender is the sender passed in from prepareForSegue:

How to find indexPath for tapped accessory button in tableView

Community
  • 1
  • 1
Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75