Up vote 0 down vote favorite 1 share g+ share fb share tw.
I wrote the following snippet according to The iPhone Developer's Cookbook C5 - Tables 07a - Delete: -(void)viewDidLoad{ history=NSMutableArray allocinitWithObjects:@"a",@"b",@"c",@"d",@"e",nil; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSLog(@"return %d",history count); return history count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell=self. TableView dequeueReusableCellWithIdentifier:@"any-cell"; if(cell==nil) cell=UITableViewCell allocinitWithFrame:CGRectZero reuseIdentifier:@"any-cell"autorelease; cell.textLabel. Text=history objectAtIndex:indexPath row; cell.textLabel.
TextColor=UIColor blackColor; cell. AccessoryType=UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"history count=%d",history count); NSLog(@"indexPath row=%d",indexPath row); history removeObjectAtIndex:indexPath row; tableView deleteRowsAtIndexPaths:NSArray arrayWithObject:indexPath withRowAnimation:UITableViewRowAnimationFade; } after building, I pressed the "edit" button on the navigation bar and there showed a red "-" for deletion. But nothing on screen changed.
After multiple "-" hits, the app crashed. The output is: > 2011-07-13 05:16:34.128 test13141:207 return 5 2011-07-13 05:16:311-07-13 > 05:16:37.909 test13141:207 history count=5 2011-07-13 05:16:37.910 > test13141:207 indexPath row=0 2011-07-13 05:16:39.069 > test13141:207 history count=4 2011-07-13 05:16:39.070 > test13141:207 indexPath row=0 2011-07-13 05:16:39.653 > test13141:207 history count=3 2011-07-13 05:16:39.654 > test13141:207 indexPath row=0 2011-07-13 05:16:311-07-13 > test13141:207 history count=2 2011-07-13 05:16:40.070 > test13141:207 indexPath row=0 2011-07-13 05:16:311-07-13 > test13141:207 history count=1 2011-07-13 05:16:40.510 > test13141:207 indexPath row=0 2011-07-13 05:16:311-07-13 > test13141:207 history count=0 2011-07-13 05:16:41.582 > test13141:207 indexPath row=0 2011-07-13 05:16:311-07-13 > test13141:207 *** Terminating app due to uncaught exception > 'NSRangeException', reason: '*** -NSMutableArray > removeObjectAtIndex:: index 0 beyond bounds for empty array' > *** Call stack at first throw: ( > 0 CoreFoundation 0x00db3be9 __exceptionPreprocess + 185 > 1 libobjc.A. Dylib 0x00f085c2 objc_exception_throw + 47 > 2 CoreFoundation 0x00dacadf -__NSArrayM removeObjectAtIndex: + 415 > 3 Â?
ÈËaæáßò‰? ¶ 0x00004614 -CallHistory tableView:commitEditingStyle:forRowAtIndexPath: + 182 > 4 UIKit 0x003262ea -UITableView(UITableViewInternal) animateDeletionOfRowWithCell: + 101 > 5 UIKit 0x002bca6e -UIApplication sendAction:to:from:forEvent: + 119 > 6 UIKit 0x0034b1b5 -UIControl sendAction:to:forEvent: + 67 > 7 UIKit 0x0034d647 -UIControl(Internal) _sendActionsForEvents:withEvent: + 527 > 8 UIKit 0x0034c1f4 -UIControl touchesEnded:withEvent: + 458 > 9 UIKit 0x002e10d1 -UIWindow _sendTouchesForEvent: + 567 > 10 UIKit 0x002c237a -UIApplication sendEvent: + 447 > 11 UIKit 0x002c7732 _UIApplicationHandleEvent + 7576 > 12 GraphicsServices 0x016e9a36 PurpleEventCallback + 1550 > 13 CoreFoundation 0x00d95064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 > 14 CoreFoundation 0x00cf56f7 __CFRunLoopDoSource1 + 215 > 15 CoreFoundation 0x00cf2983 __CFRunLoopRun + 979 > 16 CoreFoundation 0x00cf2240 CFRunLoopRunSpecific + 208 > 17 CoreFoundation 0x00cf2161 CFRunLoopRunInMode + 97 > 18 GraphicsServices 0x016e8268 GSEventRunModal + 217 > 19 GraphicsServices 0x016e832d GSEventRun + 115 > 20 UIKit 0x002cb42e UIApplicationMain + 1160 > 21 Â? ÈËaæáßò‰?
¶ 0x2011-07-13 05:16:311-07-13c main + 106 > 22 Â? ÈËaæáßò‰? ¶ 0x00002229 start + 53 > 23?
0x02011-07-13 05:16:311-07-13 0x0 + 1 ) terminate called after throwing an instance of 'NSException' the NSLog showed that history(which is a NSMutableArray) have been changed actually. I built The iPhone Developer's Cookbook C5 - Tables 07a - Delete and found a similar crash happened, where tableView: numberOfRowsInSection: was called only once. But DeleteMeController in Beginning iPhone 3 Development 09 Nav successfully deleted a row and tableView: numberOfRowsInSection: was called every time once tableView: commitEditingStyle: forRowAtIndexPath: was called.
IPhone Developer's Cookbook's code was wrote manually, and Beginning iPhone 3 Development used Interface Builder. Any clues on whats wrong? Im really confused... Thanks for reading this!
Cheers,Lloyd uitableview delete crash row link|improve this question asked 2011-07-13 05:16:311-07-13 at 14:27DamningGodson33.
(void)tableView:(UITableView *)tableView commitEditingStyle: UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { history removeObjectAtIndex:indexPath. Row; tableView deleteRowsAtIndexPaths:NSArray arrayWithObject:indexPath withRowAnimation:UITableViewRowAnimationMiddle; tableView endUpdates; tableView reloadData; } }.
Yeah with tableView endUpdates; tableView reloadData; it worked! Thank you kalpesh! – DamningGodson Jul 13 '11 at 0:15 with only tableView endUpdates; it also worked good!
– DamningGodson Jul 13 '11 at 0:18.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.