0

I am using a fetchresultscontroller returning distinct results (NSDictionaryResultType) which has multiple sections and rows in each section. When I use indexPathForSelectedRow it returns null. Here is my code:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{       
    if ([segue.identifier isEqualToString:@"toDetailViewSeg"]){
        WLDetailTableViewController *detailController =segue.destinationViewController;
        WeightLiftingInfo *theInfo = [[_fetchedResultsController fetchedObjects] objectAtIndex:self.tableView.indexPathForSelectedRow.row];
        detailController.muscleGroupInfo = [theInfo valueForKey:@"muscleGroup"];
        detailController.specificExerciseInfo = [theInfo valueForKey:@"specificExercise"];
        detailController.managedObjectContext = _managedObjectContext;
    }

}

How do I get the correct index path??

Ron
  • 24,175
  • 8
  • 56
  • 97
RyGuy
  • 37
  • 1
  • 6
  • 1
    This question looks suspiciously similar ([link](http://stackoverflow.com/q/9073309/335858)). I am not 100% sure, so I wouldn't vote on closing this as a duplicate. – Sergey Kalinichenko Jun 19 '12 at 21:43
  • Please remove the branch of the `if`-statement that doesn't get executed. – David Rönnqvist Jun 19 '12 at 21:46
  • Try using `[sender indexPathForSelectedRow]` as suggested by _a comment_ to [this answer](http://stackoverflow.com/a/8130716/608157) – David Rönnqvist Jun 19 '12 at 21:51
  • The title is very identical, but the situation I believe, is different. The IndexPathForSelectedRow worked perfectly until I wanted to fetch distinct results. I was thinking it might have to do with the return result being an NSDictionary?? – RyGuy Jun 19 '12 at 22:10
  • @DavidRönnqvist `[sender indexPathForSelectedRow]` throws an invalidargumentexception – RyGuy Jun 19 '12 at 22:21
  • Try `NSLog(@"Sender: %@", [sender class]);` so we can see what's actually triggering the seque. – Phillip Mills Jun 19 '12 at 22:28
  • @PhillipMills the class triggering it is `UITableViewCell` – RyGuy Jun 19 '12 at 22:30
  • 1
    I tried the following code and it is working again. Thank you for your help! `WeightLiftingInfo *theInfo = [_fetchedResultsController objectAtIndexPath:self.tableView.indexPathForSelectedRow];` – RyGuy Jun 19 '12 at 22:35
  • @user1410832 Nice. Post it as answer to your own question (if it was your solution) and accept it so that people know that there is an answer for your question. – David Rönnqvist Jun 19 '12 at 22:38
  • @DavidRönnqvist SO tells me I cant answer my own question until 8 hours after the original post due to my low reputation ( I'm new here). I posted the answer, but SO wont let me accept it until tomorrow. Thanks for the help! – RyGuy Jun 20 '12 at 15:50

1 Answers1

0
WeightLiftingInfo *theIndo = [_fetchedResultsController objectAtIndexPath:self.tableView.indexPathForSelectedRow];

This seems to be the answer. It provides the correct index path which looks like a set [x,y] instead of a single integer. (this is my interpretation which may be wrong)

RyGuy
  • 37
  • 1
  • 6