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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:19:41+00:00 2026-05-31T06:19:41+00:00

My app has a UITableViewController that is getting an Invalid Update: invalid number of

  • 0

My app has a UITableViewController that is getting an “Invalid Update: invalid number of rows in section 0…” after appending rows. Thing is, it happens only in %0.2 of sessions. Our app, has millions of sessions so the crashes are adding up.

The flow is simple. It’s part of a feature that matches a user’s music with our catalog of videos. A background thread makes a series of requests. A request goes out, response comes back with results, then those results get appended to a tableView within one of our tabs. The requests go in batches and can add up to lots of resulting rows. So rather than call reloadData after a batch comes in, I wanted to append them properly. Works awesome, but occasionally crashes.

I was able to reproduce this one time on a device. It has never happened on simulator. As far as I know, the crash is reasonably random, although it mostly happens on 3gs. The fewest # of crashes come from 4s.

Here’s the code. A response comes back. In this case, allMatches is every match so far (the data source for the table). batchMatches is the number of new artists. Both are arrays:

    [self.tableView beginUpdates];
    NSMutableArray *paths = [[NSMutableArray alloc] init];
    for (int i = [allMatches count] - [batchMatches count]; i < [allMatches count]; ++i) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];        
        [paths addObject: indexPath];
    }
    [self.tableView insertRowsAtIndexPaths:paths withRowAnimation:NO]; 
    [self.tableView endUpdates];
    [paths release];

Code is pretty simple. It just appends rows to the end, one for each result. Never deletes. An example of full exception message is “Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (131) must be equal to the number of rows contained in that section before the update (131), plus or minus the number of rows inserted or deleted from that section (20 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).” Numbers are all over the place in actual crash reports, so it’s not a specific batch number.

Like I said, it almost always works. And it crashes usually on 3GS. I’m wondering if this could possibly be a framework bug. I could always call reloadData after each batch returns but it results in ugly flashing of table cells each time. On purpose I triggered the exception and it seems after that the table is dead, so I couldn’t do a try/catch with a reloadData as a fallback in the catch block.

Can anyone out there shed some light? Apologies for length of this post.

EDIT: The server requests are done using NSOperationQueue, so they are on a background thread. When the response returns, I post a notification on the main thread, which causes the table code to run. The notification is posted like this:

NSNotification *notification = [NSNotification notificationWithName:notificationName object:self];
[self performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:NO];  

Post notificiation is simply a wrapper around [[NSNotificationCenter defaultCenter] postNotification:notification]. So the table code should be on the main thread.

  • 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-31T06:19:42+00:00Added an answer on May 31, 2026 at 6:19 am

    My guess is, you are executing the table view update in a background thread. You should do that on the main thread instead.

    Place your code inside a dispatch_async block.

    dispatch_async(dispatch_get_main_queue(), ^(void) {
           // ..
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPad app that has a UITableViewController that implements the NSFetchedResultsControllerDelegate .
Our app has a UITableViewController with some custom section headers. These section headers are
I'm developing an app that has an UITableViewController with static cells . Those static
In my app I am pushing a view controller (a UITableViewController) that has also
My app has a session timeout after 30 minutes. If the user has a
My app has some table cells that vary in height. The cells can also
My application has a view controller that extends UITableViewController . The initialization method looks
In my iPhone app I have a UIViewController that has a UITableView and another
I have a MonoTouch iPhone app which has a UITableViewController as it's main view
While I'm testing my app, is an UITableViewController navigation based app, sometimes, getting back

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.