Search code examples
iphoneobjective-ciosuitableviewdelegation

How to get custom NSManagedObject subclass from selected UITableViewCell


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.


Solution

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