Delete a row from Core Data UITableView with custom button

Discussion in 'iOS Programming' started by mdhansen5, Jun 13, 2012.

  1. mdhansen5 macrumors member

    Nov 22, 2010
    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. :)
  2. CodeBreaker, Jun 14, 2012
    Last edited: Jun 14, 2012

    CodeBreaker macrumors 6502

    Nov 5, 2010
    Sea of Tranquility
    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.

Share This Page