Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:57:25+00:00 2026-06-05T13:57:25+00:00

I have a UITableView that is populated with cells by core data and an

  • 0

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.

EDIT:

This is the code I have to delete it using standard swipe-to-delete. Any way I could modify it to work with a button?

if (editingStyle == UITableViewCellEditingStyleDelete) {

    [self.tableView beginUpdates];

    // Delete the task 
    Task *taskToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSLog(@"Deleting (%@)", taskToDelete.name);
    [self.managedObjectContext deleteObject:taskToDelete];
    [self.managedObjectContext save:nil];

    // Delete the row 
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [self performFetch];

    [self.tableView endUpdates];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:57:27+00:00Added an answer on June 5, 2026 at 1:57 pm

    General overview:

    1. Connect the button to an action on your controller, deleteRow:(id)sender;
    2. The sender will be the button. Get its superview, then the superview of its superview, and so on until you have a reference to the UITableViewCell. (Search in a loop using isKindOfClass:, don’t assume the button is only 1, 2, 3 levels down.)
    3. Call your table view’s indexPathForCell: method to convert the cell reference to an index path.
    4. Use objectAtIndexPath: on the fetched results controller to get the object.

    Then delete it! If you are handling the NSFetchedResultsController delegate methods they will take care of removing the deleted row.

    Sample code (typed without a compiler to check it):

    - (void)deleteRow:(id)sender
    {
        id view = [sender superview];
        while (view && ![view isKindOfClass:[UITableViewCell class]]) {
            view = [view superview];
        }
        UITableViewCell *cell = view;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
        NSManagedObject *task = [fetchedResultsController objectAtIndexPath:indexPath];
        [self.managedObjectContext deleteObject:task];
        [self.managedObjectContext save:nil];
    }
    

    That’s it. DO NOT try to remove the row from the table view. When the object is deleted, NSFetchedResultsController will detect the change and update your table view, assuming you set up the delegate methods as described in the documentation for NSFetchedResultsController. If you haven’t, read the documentation (just option-double-click on “NSFetchedResultsController” in Xcode).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app, I have a UITableView that is populated by Core Data, currently
I have a UITableView that is being populated by core data. Now, when I
I have a UITableView that is populated with custom cells (inherited from UITableViewCell ),
I have a UITableView that is populated with cells of a variable height. I
I have a UITableView populated with custom UITableViewCells. Within those custom cells, I have
I have an UITableview which has a description cell populated by an NSString ,
I have a UITableView which is populated with some parsed JSON twitter data. The
I have UITableView that contains many cell. User can expand cell to see more
I have a UItableView that segues to a different view controller. I'm using a
I have a UITableView that I use to send an email using MFMailComposeViewController. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.