views:

120

answers:

1

Having meticulously followed the examples and instructions in the Table View Programming Guide for iOS about the proper order in which UITableView delegate and data source methods are called, I thought I had a good idea of how to implement the “handshake” shown in Figure 7-1 and the list that follows, but apparently not.

Here's the code I'm using…

- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath {
    NSLog(@"Removing %@ row %d.", [dataModel objectAtIndex: indexPath.row], indexPath.row);
    [tableView deleteRowsAtIndexPaths: [NSArray arrayWithObjects: indexPath, nil] withRowAnimation: UITableViewRowAnimationFade];
    [dataModel removeObjectAtIndex: indexPath.row];
}

tableView is the UITableView
dataModel is an NSArray instance that holds the objects represented by the UITableViewCells from the tableView.

…and the error I'm getting…

2010-08-27 21:53:17.971 SportWatch[1299:307] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1262.58/UITableView.m:920
2010-08-27 21:53:17.992 SportWatch[1299:307] *** 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 (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x35411ed3 __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x311f0811 objc_exception_throw + 24
    2   CoreFoundation                      0x35411d15 +[NSException raise:format:arguments:] + 68
    3   Foundation                          0x332b932f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
    4   UIKit                               0x338dcda1 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 4524
    5   UIKit                               0x338d586d -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 204
    6   UIKit                               0x338d5775 -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 20
    7   SportWatch                          0x000060e7 -[MainViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 670
    8   UIKit                               0x338d3c3f -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] + 58
    9   UIKit                               0x33984071 -[UITableViewCell(UITableViewCellInternal) deleteConfirmationControlWasClicked:] + 28
    10  CoreFoundation                      0x353b9719 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
    11  UIKit                               0x33831d59 -[UIApplication sendAction:to:from:forEvent:] + 84
    12  UIKit                               0x33831cf9 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
    13  UIKit                               0x33831ccb -[UIControl sendAction:to:forEvent:] + 38
    14  UIKit                               0x33831a1d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
    15  UIKit                               0x3383206b -[UIControl touchesEnded:withEvent:] + 342
    16  UIKit                               0x338309f5 -[UIWindow _sendTouchesForEvent:] + 368
    17  UIKit                               0x3383036f -[UIWindow sendEvent:] + 262
    18  UIKit                               0x3382ae13 -[UIApplication sendEvent:] + 298
    19  UIKit                               0x3382a74b _UIApplicationHandleEvent + 5110
    20  GraphicsServices                    0x3171a04b PurpleEventCallback + 666
    21  CoreFoundation                      0x353a6ce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    22  CoreFoundation                      0x353a6ca7 __CFRunLoopDoSource1 + 166
    23  CoreFoundation                      0x3539956d __CFRunLoopRun + 520
    24  CoreFoundation                      0x35399277 CFRunLoopRunSpecific + 230
    25  CoreFoundation                      0x3539917f CFRunLoopRunInMode + 58
    26  GraphicsServices                    0x317195f3 GSEventRunModal + 114
    27  GraphicsServices                    0x3171969f GSEventRun + 62
    28  UIKit                               0x337d148b -[UIApplication _run] + 402
    29  UIKit                               0x337cf69f UIApplicationMain + 670
    30  SportWatch                          0x00002b23 main + 70
    31  SportWatch                          0x00002ad8 start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
kill
Current language:  auto; currently objective-c
quit
+1  A: 

remove the object from the data set before deleting the row.

thelaws
It wasn't only this, and from what I've read, it has to do with the `-tableView:numberOfRowsInSection:` method from the `UITableView`'s data source.
Alexsander Akers
Thanks irregardless.
Alexsander Akers