0

I have a UITableView in my app that displays some Location objects which I have created as part of a Core Data store. The UITableViewCell actually just displays the name of the Location (one of the properties on the Location object). When the user selects a Location, I want to use delegation to pass the Location object to the previous view controller, not just the text that's in the cell.

I am trying to think of the best way to do this and can create a new Location object to pass back, but don't know how I would get the actual object who's text was being displayed in the UITableViewCell.

Thanks for any suggestions.

Jamie
  • 5,090
  • 28
  • 26

2 Answers2

1

Take a look at NSFetchedResultsController. It is meant to do exactly what you want: displaying Core Data objects in a table view.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
  • Thanks very much. I was using a FetchedResultsController to display the cells but didn't think of it for the selection. I did : Location *selectedLocation = [self.fetchedResultsController objectAtIndexPath:indexPath]; and it works great. – Jamie Jun 30 '12 at 22:10
1

If you have populated your TableView with an array (like from a FetchRequest), then using

MyManagedObjectSubclass *selectedManagedObject = [myDataSourceArray objectAtIndex:indexPath.row];

in your didSelectRowAtIndexPath delegate method will get you what you need.

LJ Wilson
  • 14,445
  • 5
  • 38
  • 62