So far, this is how my app works: the user types in a web address, and as they type, the app tries to scan pages for RSS feeds. To do this, quickly and without blocking the main thread, it creates a bunch of NSOperations running on their own threads, plus a Queue to manage them.
As each operation finishes scanning an RSS feed, it calls this method in my table view controller:
feeds is an NSMutableArray iVar.
promptUpdate just updates the search prompt. (By using the prompt, I don't need to bother with inserting a cell that tells the user what's going on.)
My number of rows method is this:
And I only have a single section, so the number of section method just returns 1 always.
My app works perfectly somewhere around 40% of the time, but I'd say 60% of the time it prints out something like this:
It seems to me that my method should work all the time, because it always starts with a call to the tableView to beginUpdates, which locks it from being edited by other threads, correct?, it follows it up with the data being edited and the new row being inserted, and then it ends with an endUpdates. I don't see how it's possible for me to end up with a different count in my datasource vs. in my view? (If you need more code than I've provided, I'll be happy to share.)
As each operation finishes scanning an RSS feed, it calls this method in my table view controller:
Code:
-(void)searchGotRSS:(NSDictionary*)dictionary {
[self.tableView beginUpdates];
[feeds addObject:dictionary];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[feeds count]-1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
[self promptUpdate];
}
feeds is an NSMutableArray iVar.
promptUpdate just updates the search prompt. (By using the prompt, I don't need to bother with inserting a cell that tells the user what's going on.)
My number of rows method is this:
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [feeds count];
}
And I only have a single section, so the number of section method just returns 1 always.
My app works perfectly somewhere around 40% of the time, but I'd say 60% of the time it prints out something like this:
Code:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1914.84/UITableView.m:1037
2012-09-13 23:55:50.560 FeedReader[29052:8003] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) 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 (1 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 seems to me that my method should work all the time, because it always starts with a call to the tableView to beginUpdates, which locks it from being edited by other threads, correct?, it follows it up with the data being edited and the new row being inserted, and then it ends with an endUpdates. I don't see how it's possible for me to end up with a different count in my datasource vs. in my view? (If you need more code than I've provided, I'll be happy to share.)
Last edited: