Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdhansen5

macrumors member
Original poster
Nov 22, 2010
43
0
Colorado
I have a UITableView that is populated with cells by core data and an NSFetchedResultsController. I have a custom button on my custom cells, which I'm planning on using to delete the cell. It's very easy to add the standard swipe-to-delete, but I'd rather use this custom button. Does anyone know how I could hook up an action to the button that would delete the entry from the data model and delete the cell from the UITableView? I cannot find a good solution to this for the life of me. :)
 
I assume that you have a UITableViewCell subclass. The next thing would be to add a button on the cell and make it post a notification when tapped. Add the indexPath of the cell in the notification's userInfo.

The notification will be received by your Table View Controller. After that you can get the managed object at the index path using your fetched results controller. Then it's just delete and save context.

You can, intact, just use deleteRowsAtIndexPath: withRowAnimation: and let your fetched results controller handle the changes, if you have implemented the fetched results controller delegate methods.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.