Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>this error occurs because the <code>dataSource</code> count isn't the same like the actual data. When you delete an item the <code>tableView</code> cells will go down eg. from 10 to 9. But you didn't delete the data from your <code>dataSource</code> so you end up with different <code>count</code> and Xcode poke you a little.</p> <p>As talked (extensively) in chat we got the problem solved with this code:</p> <pre><code>- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [tableView beginUpdates]; NSIndexPath *realIndex = [self realIndexPathForIndex:indexPath]; NSArray *plist = [self readFullPlist]; NSMutableDictionary *theItem = [[[plist objectAtIndex:realIndex.section] valueForKey:@"Rows"] objectAtIndex:realIndex.row]; [theItem setValue:[NSNumber numberWithBool:NO] forKey:@"isFav"]; [self writePlist:plist]; [self refreshTable]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView endUpdates]; } } - (NSArray*)readFullPlist { NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *plistPath = [[documentPaths lastObject] stringByAppendingPathComponent:@"tipsList.plist"]; NSFileManager *fMgr = [NSFileManager defaultManager]; if (![fMgr fileExistsAtPath:plistPath]) { NSString *bundlePlistPath = [[NSBundle mainBundle] pathForResource:@"tipsList" ofType:@"plist"]; [self writePlist:[NSArray arrayWithContentsOfFile:bundlePlistPath]]; } return [NSArray arrayWithContentsOfFile:plistPath]; } - (NSIndexPath*)realIndexPathForIndex:(NSIndexPath*)idxPath { NSArray *fullList = [self readFullPlist]; NSArray *subArr = [[fullList objectAtIndex:idxPath.section] objectForKey:@"Rows"]; int row = idxPath.row; int newRow = 0; for (NSDictionary *dic in subArr) { if ([[dic valueForKey:@"isFav"] boolValue]) { if (row == 0) { return [NSIndexPath indexPathForRow:newRow inSection:idxPath.section]; } row--; } newRow++; } return idxPath; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload