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 7173247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:47:05+00:00 2026-05-28T15:47:05+00:00

This is my code to delete a cell in my UITableView: – (void)tableView:(UITableView *)tableView

  • 0

This is my code to delete a cell in my UITableView:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView beginUpdates];

    if([tableView numberOfRowsInSection:[indexPath section]] > 1) {
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
            withRowAnimation:UITableViewRowAnimationFade];
    } else {
        [tableView deleteSections:[NSIndexSet indexSetWithIndex:[indexPath section]] 
            withRowAnimation:UITableViewRowAnimationFade];
    }

    [tableView endUpdates];
}

There is also some data being updated before the cell is deleted, but I’m rather sure it is being updated properly because the count of the data source’s array is always one less each time a cell is deleted. This is the expected behavior. Yet for some reason, whenever I delete the last cell in a section, I get 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

It is incredibly frustrating, especially because from what I have been able to find on the Internet, I am doing this correctly. Maybe I need sleep, it’s been a while. Any ideas here?

Solution:

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    if(tableIsEmpty) {
        //**this** line was the culprit- returning zero here fixed the problem
        return 0;
    } else if(section == ([tableView numberOfSections] - 1)) {
        //this is the last section- it only needs one row for the 'Delete all' button
        return 1;
    } else {
        //figure out how many rows are needed for the section
    }
}
  • 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-05-28T15:47:06+00:00Added an answer on May 28, 2026 at 3:47 pm

    Your problem lies in the implementation of your numberOfRowsInSection: method. Your deletion seems to be fine. When you’ve deleted the rows, I think you are failing to update the source used to return the number of rows in the numberOfRowsInSection: method. Because of the inconsistency there, you get the error. Please share that code.

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

Sidebar

Related Questions

This is the abridged code for my cellForRowAtIndexPath UITableView delegate method: - (UITableViewCell*)tableView:(UITableView *)tableView
This code will delete the entire row if it finds an empty cell in
This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
This code leads to undefined behavior: void some_func() { goto undefined; { T x
I'm using this code to delete a UITableViewCell, but when I swipe to delete,
I added my state to m. This code will delete mystate? QStateMachine *m =
Why does this code delete only even elements within the array? I would expect
I have this code $(.delete2).click(function() { $('#load2').fadeIn(); } I have dynamically added item via
This code in JS gives me a popup saying i think null is a
This code is from Prototype.js . I've looked at probably 20 different tutorials, and

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.