Approval error in - [UITableView _endCellAnimationsWithContext:]

Hope this will be a quick fix. I tried to figure out the error that I keep getting. The error is listed below, and appdelagate is below.

Any help is appreciated.

thank

2012-04-12 21:11: 52.669 Chanda [75100: f803] --- Approval error in -[UITableView _endCellAnimationsWithContext:] , /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037 2012-04-12 21: 11: 52.671 Chanda [75100: f803] --- Application terminated due to an uncaught exception ' NSInternalInconsistencyException ', reason: 'Invalid update: invalid number of lines in section 0. The number of lines in an existing section after update (2) must be equal to the number rows contained in this section before updating (2), plus or minus the number of rows inserted or deleted from this section (1 inserted, 0 deleted) and plus or minus the number of rows moved to or from this section (0 moved, 0 moved).

 #import "AppDelegate.h" @implementation AppDelegate @synthesize window = _window; @synthesize databaseName,databasePath; - (BOOL)application: (UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { self.databaseName = @"Customers.db"; NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentDir = [documentPaths objectAtIndex:0]; self.databasePath = [documentDir stringByAppendingPathComponent:self.databaseName]; [self createAndCheckDatabase]; return YES; } - (void)createAndCheckDatabase { BOOL success; NSFileManager *fileManager = [NSFileManager defaultManager]; success = [fileManager fileExistsAtPath:databasePath]; if (success) return; NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:self.databaseName]; [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; } @end 
+80
ios objective-c uitableview crash
Apr 13 '12 at 3:27
source share
12 answers

I see no reason for you to show us this part of the code. Your mistake should be related to this part of your code. I guess

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

You may be mistaken in one of these data source methods. It is currently impossible to say what exactly is wrong, but I suppose it could be something like: you are talking about the table view in numberOfRowsInSection , you would like to have n rows reserved and configured, and in cellForRowAtIndexPath you only process n - 1 line, for example.

Sorry that this answer may not be as accurate as it should be. If you show us your implementation of your data source, it would be much easier to tell what is happening.

+41
Jun 14 '12 at 7:50
source share

Like Sun Tzu said : it’s better to win without fighting. In my case, whenever I see such an error message (i.e. mismatch between added lines, etc.). I don’t even debug anything. I just do not make an extra call where I reload the lines, etc., which is 99% of the cases where this error occurs.

This is a common scenario when this error occurs: I have a UINavigationController and it has a UITableView , when I click on a row, it clicks a new UITableView and so on. This error always happens to me when I exit the last UITableView and return to the UITableView before that, at this moment I make an unnecessary call to the loadIt function, which basically inserts rows and redirects the UITableView .

The reason for this is because I mistakenly put the loadIt function in viewDidAppear:animated , not viewDidLoad . viewDidAppear:animated is called every time a UITableView displayed, viewDidLoad is called only once.

+24
Apr 2 '13 at
source share

When deleting rows, remember that it also checks for partitions when updating:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView 

If you want to delete the row that is the last element in the section, you need to delete the entire section (otherwise, this may lead to a section error and throw this exception).

+22
Jan 04 '13 at 16:42
source share

Remember to update the array that defines numberOfRowsInSection. It must be updated before you animate and delete

We check to see if the number of rows in a section is 1, because we will need to delete the entire section.

Correct me if anyone can make this answer clearer.

 [self.tableView beginUpdates]; if ([tableView numberOfRowsInSection:indexPath.section] == 1) { [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; } else { [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; } [self.tableView endUpdates]; 
+6
Nov 12 '14 at 11:44
source share

I put each element of the section into separated arrays. Then put them in another array (arrayWithArray). My solution here is for this problem:

 [quarantineMessages removeObject : message]; [_tableView beginUpdates]; if([[arrayWithArray objectAtIndex: indPath.section] count] > 1) { [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indPath] withRowAnimation:UITableViewRowAnimationBottom]; } else { [_tableView deleteSections:[NSIndexSet indexSetWithIndex:indPath.section] withRowAnimation:UITableViewRowAnimationFade]; } [_tableView endUpdates]; 
+4
Mar 29 '13 at 11:48
source share

I had the same error.

I used the following lines

 UINib *myCustomCellNib = [UINib nibWithNibName:@"CustomNib" bundle:nil]; [tableView registerNib:myCustomCellNib forCellReuseIdentifier:@"CustomNib"]; 

to register nib in the viewDidLoad method, since I had a different icon that was also associated with the same class. Hence the line

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GBFBLoadingCell"]; 

returned zero if I did not register nib in viewDidLoad.

My problem was that I forgot to set the identifier in the attribute inspector for my file "CustomNib.xib" and "CustomNib ~ iphone.xib". (Or, more precisely, I forgot to press enter after entering the identifier in the attribute inspector in Xcode, so that the new name could not be saved.)

Hope this helps.

+2
Jun 17 '13 at 10:23
source share

I had the same error that when I tried using [tableView reloadData] worked fine. The error was in line

 [TabView insertRowsAtIndexPaths:indexPathsArray withRowAnimation:UITableViewRowAnimationRight]; 

When I tried to check the indexPath values, they were incorrect as needed.

I fixed it by changing the values ​​in indexPathsArray .

Hope this helps.

+2
May 31 '16 at 11:45
source share

If you use NSFetchedResultsController as I do and update the data in the background thread, be sure to start and end the updates in the delegate:

 - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [self.tableView beginUpdates]; } - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { [self.tableView endUpdates]; } 
+1
Jan 22 '16 at 23:59
source share

I had the same problem with a Core database. If you use a lot of FRC, you just need to reload the tableview inside each condition in numberOfSectionsInTableView.

0
Oct 30 '13 at 4:39 on
source share

I just happened to me using Swift and a FRC-enabled data warehouse to manage information. Adding a simple check to the delete operation to evaluate the current indexPath.section allowed me to avoid an extraneous call. I think I understand why this problem occurs ... Basically, I load the message to the top line whenever my dataset is empty. This throws an exception to one problem, since there is a faux string.

My decision

 ... delete my entity, save the datastore and call reloadData on tableView //next I add this simple check to avoid calling deleteRows when the system (wrongly) determines that there is no section. if indexPath.section > 0 { tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .None) } 
0
Feb 22 '15 at 3:33
source share

Its may be one of the protocol methods UITableViewDataSource

For

 - tableView:numberOfRowsInSection: 

it must return an integer equal to the sum or result

-insertRowsAtIndexPaths:withRowAnimation: and / or -deleteRowsAtIndexPaths:withRowAnimation :

For

 - numberOfSectionsInTableView: 

it must return an integer equal to the sum or result

-insertRowsAtIndexPaths:withRowAnimation: and / or -deleteSections:withRowAnimation:

0
Jan 17 '16 at 7:30
source share

Just make sure you call [yourTableView reloadData]; after changing the array of values.

0
Apr 7 '16 at 14:26
source share



All Articles