UITableView crashes when deleting items at the end

I have a UITableView with a bunch of sections / rows. I get strange errors when, when I delete a line, my program crashes. My removal code is as follows:

[self.tableView beginUpdates]; NSMutableArray* myArray = [self.myArray mutableCopy]; [myArray removeObjectAtIndex:indexPath.row]; self.myArray = myArray; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; 

The debugger gives me an error on endUpdates with the following error.

* Application termination due to an uncaught exception 'NSInvalidArgumentException', reason: '* - [__ NSArrayM insertObject: atIndex:]: object cannot be nil'

Now, to save all the time, I thoroughly tested and verified that everything is absolutely correct with updating my data source and deleting the right indexPath. I just noticed that the problem only occurs when I scroll to the end of my table view, so that I can no longer scroll and then delete the cell in the visible area of ​​the page.

I can delete properly anywhere else in my table view if there is more off-screen content under it, but as soon as I am at the end of the table, this error will be deleted.

If this helps, I basically have a UITableViewController (simple style) in the UIPageViewController . I tried to remove the UIPageViewController and just click on the UITableViewController, but this error still occurs.

Does anyone know how I can overcome this?

EDIT:

It seems like many people still think it could be an array, but here's what. I can move partitions in my table view (all partitions have rows that can be deleted). I always get a crash when deleting rows in any visible section when the table view scrolls all the way down. This piece of code is abstracted and used in all sections, so I'm sure the code is correct.

When I delete a row in the section where the tableview is centered in the middle, I noticed that the row scrolls before deleting, although I said to use the fade animation. Animating the animation of the lines or sections below it, which is the correct behavior. I feel this may be due to the fact that when the tableview is at the end of its contents, it is trying to scroll something, but there is nothing there.

HACK: Now the HACK: I implemented now is a simple UIView of the same size as my tableView in tableView.tableFooterView. This leads to the fact that my TableView has a more scrollable size, which I DO NOT like, but it does not crash with it, since there is more scrollable space to move upward when deleting the last cell. I would appreciate a decision in which I should not do this.

Well, it looks like this works if the footer view is very large. If you reduce the footer, for example 100 pixels, it will still work if you scroll to the edge of the table.

Stack Trace: (The debugger will first work in the endUpdates line in the above code, and when I click the game on the debugger again, this stack trace)

 2014-07-18 05:52:41.314 ScriptChart[26419:905949] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation 0x0000000109c9f055 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010d1d8a1c objc_exception_throw + 45 2 CoreFoundation 0x0000000109b6d92a -[__NSArrayM insertObject:atIndex:] + 954 3 UIKit 0x000000010b86c424 __46-[UITableView _updateWithItems:updateSupport:]_block_invoke915 + 177 4 UIKit 0x000000010b803a4c +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 473 5 UIKit 0x000000010b803ca1 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 57 6 UIKit 0x000000010b86bfc3 -[UITableView _updateWithItems:updateSupport:] + 2803 7 UIKit 0x000000010b8660b2 -[UITableView _endCellAnimationsWithContext:] + 11934 8 ScriptChart 0x000000010863f272 -[SCLabListNoteSection deleteCell:] + 1250 9 ScriptChart 0x00000001085e127f __45-[SCLabPanelTableViewCell infoButtonPressed:]_block_invoke127 + 207 10 UIKit 0x000000010b9e0fe7 -[UIAlertController _fireOffActionOnTargetIfValidForAction:] + 55 11 UIKit 0x000000010b9e14d5 __85-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:]_block_invoke + 30 12 UIKit 0x000000010b892bc4 -[UIPresentationController transitionDidFinish:] + 1118 13 UIKit 0x000000010b894d8e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 133 14 UIKit 0x000000010bec4123 -[_UIViewControllerTransitionContext completeTransition:] + 110 15 UIKit 0x000000010b8037fd -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 326 16 UIKit 0x000000010b7ec42a -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 209 17 UIKit 0x000000010b7ec760 -[UIViewAnimationState animationDidStop:finished:] + 76 18 QuartzCore 0x000000010b4dff9e _ZN2CA5Layer23run_animation_callbacksEPv + 308 19 libdispatch.dylib 0x000000010d537d64 _dispatch_client_callout + 8 20 libdispatch.dylib 0x000000010d523f82 _dispatch_main_queue_callback_4CF + 941 21 CoreFoundation 0x0000000109c07ae9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 22 CoreFoundation 0x0000000109bca46b __CFRunLoopRun + 2043 23 CoreFoundation 0x0000000109bc9a06 CFRunLoopRunSpecific + 470 24 GraphicsServices 0x000000010db6cabf GSEventRunModal + 161 25 UIKit 0x000000010b792cf8 UIApplicationMain + 1282 26 ScriptChart 0x00000001085ca153 main + 179 27 libdyld.dylib 0x000000010d56c145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException 
+6
source share
2 answers

Are you calling scrollToRowAtIndexPath? This may cause a malfunction.

0
source

I found that for a UITableView, the style is simple, not grouped, solved the problem for me. You can find the setting by selecting the table in the storyboard.

fooobar.com/questions/169684 / ...

0
source

Source: https://habr.com/ru/post/972451/


All Articles