I have code like this. When I debug with exception breakpoint, it crash when I reloadRow.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
return ceil(self.folders.count/ 2);
else if (section <= self.documents.count) {
DocumentsCollection *dc = self.documents[section - 1];
return dc.attachments.count;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//..........
[cell setData:dc.attachments[indexPath.row] andReload:^{
[tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}];
}
I am using constraint in my cell and all my data are really correct. I am trying to read error message and find in here too but I don't get it. Please kindly explain how I shall do. I totally don't understand why it say
"reason: '*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'"
*** First throw call stack:
(
0 CoreFoundation 0x000000011334fd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011252d21e objc_exception_throw + 48
2 CoreFoundation 0x00000001132812eb -[__NSArrayM objectAtIndex:] + 203
3 UIKit 0x0000000110c61df6 -[UITableView _existingCellForRowAtIndexPath:] + 159
4 UIKit 0x0000000110c8555c -[UITableView _heightForRowAtIndexPath:] + 109
5 UIKit 0x0000000110ebd783 -[UISectionRowData heightForRow:inSection:canGuess:] + 263
6 UIKit 0x0000000110ec5601 -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:] + 1016
7 UIKit 0x0000000110ec5707 -[UITableViewRowData rectForGlobalRow:heightCanBeGuessed:] + 142
8 UIKit 0x0000000110ec64b9 -[UITableViewRowData globalRowsInRect:canGuess:] + 1101
9 UIKit 0x0000000110fa5cf3 -[_UITableViewUpdateSupport(Private) _visibleRowRangePlusAdjoining] + 96
10 UIKit 0x0000000110fa5dc8 -[_UITableViewUpdateSupport(Private) _faultInRealHeightsOfNeededCells] + 138
11 UIKit 0x0000000110fb81c7 -[_UITableViewUpdateSupport _setupAnimations] + 164
12 UIKit 0x0000000110c544dd -[UITableView _updateWithItems:updateSupport:] + 3054
13 UIKit 0x0000000110c4c90f -[UITableView _endCellAnimationsWithContext:] + 17960
14 UIKit 0x0000000110c63f62 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 331
15 UIKit 0x0000000126e4d4a2 -[UITableViewAccessibility reloadRowsAtIndexPaths:withRowAnimation:] + 73
16 iFeedback 0x000000010dc809ad __56-[DocumentVCWithFolder tableView:cellForRowAtIndexPath:]_block_invoke + 125
17 iFeedback 0x000000010dbeb6e8 -[DocumentDetailCell observeValueForKeyPath:ofObject:change:context:] + 552
18 Foundation 0x000000010f25bdec NSKeyValueNotifyObserver + 351
19 Foundation 0x000000010f25b687 NSKeyValueDidChange + 495
20 Foundation 0x000000010f33cb95 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:usingBlock:] + 986
21 Foundation 0x000000010f220b01 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 60
22 Foundation 0x000000010f2e80df _NSSetSizeValueAndNotify + 285
23 UIKit 0x000000011144fa84 -[UICollectionView _updateVisibleCellsNow:] + 745
24 UIKit 0x0000000111456725 -[UICollectionView layoutSubviews] + 313
25 UIKit 0x0000000110bd2ab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
26 QuartzCore 0x00000001106e6bf8 -[CALayer layoutSublayers] + 146
27 QuartzCore 0x00000001106da440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
28 UIKit 0x0000000110bc0928 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1509
29 iFeedback 0x000000010dbeb4a9 -[DocumentDetailCell setUpTag] + 553
30 iFeedback 0x000000010dbeb24a -[DocumentDetailCell setData:andReload:] + 154
31 iFeedback 0x000000010dc8078b -[DocumentVCWithFolder tableView:cellForRowAtIndexPath:] + 1995
32 UIKit 0x0000000110c7b584 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 757
33 UIKit 0x0000000110c7b7e2 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
34 UIKit 0x0000000110c4f2b0 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3295
35 UIKit 0x0000000110c84b64 -[UITableView _performWithCachedTraitCollection:] + 110
36 UIKit 0x0000000110c6b3be -[UITableView layoutSubviews] + 222
37 UIKit 0x0000000110bd2ab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
38 QuartzCore 0x00000001106e6bf8 -[CALayer layoutSublayers] + 146
39 QuartzCore 0x00000001106da440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
40 QuartzCore 0x00000001106da2be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
41 QuartzCore 0x0000000110668318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
42 QuartzCore 0x00000001106953ff _ZN2CA11Transaction6commitEv + 475
43 QuartzCore 0x0000000110695d6f _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
44 CoreFoundation 0x00000001132f4267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
45 CoreFoundation 0x00000001132f41d7 __CFRunLoopDoObservers + 391
46 CoreFoundation 0x00000001132d8f8e __CFRunLoopRun + 1198
47 CoreFoundation 0x00000001132d8884 CFRunLoopRunSpecific + 420
48 GraphicsServices 0x0000000115340a6f GSEventRunModal + 161
49 UIKit 0x0000000110b0dc68 UIApplicationMain + 159
50 iFeedback 0x000000010dc60ebf main + 111
51 libdyld.dylib 0x00000001138da68d start + 1
)
I believe the Array the error is referring to is actually the queue of reusable cells that the UITableView maintain. When you call reloadRowsAtIndexPath, the tableView will ask its delegate for another cell at the same indexPath.
By adding a log into the first and last line of cellForRowAtIndexPath my log look something like:
Start for cell at [0, 9]
Start for cell at [0, 9]
End for cell at [0, 9]
End for cell at [0, 9]
Start for cell at [0, 10]
Start for cell at [0, 10]
End for cell at [0, 10]
End for cell at [0, 10]
Start for cell at [1, 0]
Start for cell at [1, 0]
End for cell at [1, 0]
End for cell at [1, 0]
Start for cell at [1, 1]
2017-01-10 16:48:05.530 TableView[25012:201598] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 8 beyond bounds [0 .. 7]'
which shows that if the completion handler of your setData gets called before the cellForRowAtIndexPath completes, your UITableView will attempt to call for one more cell then it has - note that my error says index 8 beyond bounds [0 .. 7] and my UITableView has got 8 visible cells.
To solve the problem, I suggest not calling reloadRowAtIndexPath but instead update the values of whatever display your cell contains directly.
your code is showing error because the block in which you are setting the data might be giving little bit delay.
The summary of what i meant is that you are reloading the table view from its delegate method. And the reloading is getting called from a block which might be the reason of crash.
You can do one thing, rather then reloading specific row, try to reload whole table.
Hope it will work.
Keep it simple.
Number of Row in every section should equal to objects in Array.
Suppose you pass 4 count in section 1 (which starts at index == 0) should equal to your Array objects.
It is crashing due to ROW count and Object in array is not matching.
If it not matched than you will get
"reason: '* -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'"
Bounds [0..3] means Array has only 4 objects and it is trying to get 5th object at index 4.
Please check it and should has proper count in Array object.
Related
Application Specific Information:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -'[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 3]'
0 CoreFoundation __exceptionPreprocess + 124
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreFoundation -[__NSArrayM removeObjectAtIndex:] + 0
3 UIKit -[UITableView cellForRowAtIndexPath:] + 252
4 someApp -[businessViewClass methodA:] (businessViewClass.m:298)
5 someApp -[businessViewClass scrollViewDidScroll:] (businessViewClass.m:292)
6 UIKit -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 76
7 UIKit -[UIScrollView setContentOffset:] + 460
8 UIKit -[UITableView setContentOffset:] + 300
9 UIKit -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 60
10 UIKit -[UIScrollView setContentSize:] + 128
11 UIKit -[UITableView _applyContentSizeDeltaForEstimatedHeightAdjustments:] + 56
12 UIKit -[UITableViewRowData setHeight:forRowAtIndexPath:] + 572
13 UIKit __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 3016
14 UIKit +[UIView(Animation) performWithoutAnimation:] + 80
15 UIKit -[UITableView _configureCellForDisplay:forIndexPath:] + 460
16 UIKit -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 788
17 UIKit -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
18 UIKit -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
19 UIKit -[UITableView cellForRowAtIndexPath:] + 136
20 someApp -[businessViewClass methodA:] (businessViewClass.m:298)
21 UIKit -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 76
22 UIKit -[UIScrollView setContentOffset:] + 460
23 UIKit -[UITableView setContentOffset:] + 300
24 UIKit -[UIScrollView _smoothScrollWithUpdateTime:] + 2400
25 QuartzCore CA::Display::DisplayLinkItem::dispatch() + 40
26 QuartzCore CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 424
27 IOKit 0x000000018334de54 0x183348000 + 24148
28 CoreFoundation __CFMachPortPerform + 180
29 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
30 CoreFoundation __CFRunLoopDoSource1 + 436
31 CoreFoundation __CFRunLoopRun + 1800
32 CoreFoundation CFRunLoopRunSpecific + 384
33 GraphicsServices GSEventRunModal + 180
34 UIKit UIApplicationMain + 204
35 someApp main (main.m:15)
36 libdyld.dylib 0x0000000182b528b8 0x182b50000 + 10424
This is what happend.
I find an bug that exists in app online, but I can't reproduce it with project code. It seems a business method was called when scroll the UIScrollview, and this business method call cellForRowAtIndexPath method of UITableView, and then cellForRowAtIndexPath trigs the scrollViewDidScroll method of UIScrollView. And I call cellForRowAtIndexPath in scrollViewDiddScroll method. It comes back. but It doesn't recurrence because next method called is NSArrayM removeObjectAtIndex instead of trigging the ScrollViewDidScroll method of UIScrollView. and then NSRangeException occurred.
is there anybody meet this or any ideas? thank you.
Your numberOfRowsInSection method of tableview is returns value that is greater than your array of count.
array's count is 3 and you are accessing 5th object of array.
What you can do is put a check to avoid any such crash, just look at this example code. This will be helpful just in case you aren't able to reproduce it.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.yourArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (self.yourArray.count > indexPath.row)
{
// your code for the cell
}
return cell;
}
Your counting through an array but you are counting too far, thus not in bounds. You need to count the exact amount of units in the array.
Use this:
[_array count];
My app was working fine prior to the forced upgrade to Swift 2.x. My code below is executed on an IBAction for a button that "collapses" the cell, e.g. it replaces it with another layout and then attempts to reload the cell, which for various reasons I've been forced to include each cell in its own section (so, extensibly I'm reloading the section). I've tried outputting various variables to the terminal; the inputs are sound. I've also tried wrapping this in .beginUpdates() and .endUpdates() and when walking through this in the debugger, it will just throw the below exception on the .endUpdates() call instead of the .reloadSections() call. I have also tried replacing .reloadSections() with a blanket call to .reloadData() and I receive the same stack trace, making me believe it's internal to the TableView object somehow.
// Set Selected Patient Configuration to "Collapsed"
patientList.patients[ sender.tag ].updateConfiguration( collapsedConfiguration )
let animation = UITableViewRowAnimation.Automatic
// Retrieve Current Table View and Animate Changes
let tableView = self.superview!.superview as! UITableView
// Reload Section with Animation
tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
My code will evaluate the backing data's collapsed state and draw it in either the full or collapsed view.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x00e2fa84 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03235e02 objc_exception_throw + 50
2 CoreFoundation 0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
3 Foundation 0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
4 CoreFoundation 0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
5 CoreFoundation 0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
6 CoreFoundation 0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
7 UIKit 0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
8 UIKit 0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
9 libobjc.A.dylib 0x0324a00c -[NSObject performSelector:] + 62
10 CoreFoundation 0x00d60571 -[NSArray makeObjectsPerformSelector:] + 273
11 UIKit 0x021b06f6 -[UINib instantiateWithOwner:options:] + 2102
12 UIKit 0x01eeed6c -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 457
13 UIKit 0x01eef173 -[UITableView dequeueReusableCellWithIdentifier:] + 48
14 Halo 0x001b5174 _TFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 2356
15 Halo 0x001be459 _TToFC4Halo18MainViewController9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 89
16 UIKit 0x01f03a19 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 782
17 UIKit 0x01f03b47 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 90
18 UIKit 0x022568cc -[_UITableViewUpdateSupport(Private) _setupAnimationsForNewlyInsertedCells] + 8353
19 UIKit 0x0226181a -[_UITableViewUpdateSupport _setupAnimations] + 161
20 UIKit 0x01ed7fd3 -[UITableView _updateWithItems:updateSupport:] + 3653
21 UIKit 0x01ecfc91 -[UITableView _endCellAnimationsWithContext:] + 17491
22 UIKit 0x01eea538 -[UITableView _updateSections:updateAction:withRowAnimation:headerFooterOnly:] + 460
23 UIKit 0x01eea625 -[UITableView reloadSections:withRowAnimation:] + 73
24 Halo 0x00105e10 _TFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 6208
25 Halo 0x0010645d _TToFC4Halo28FullPatientViewTableViewCell19collapseButtonPressfS0_FCSo8UIButtonT_ + 61
26 libobjc.A.dylib 0x0324a0b5 -[NSObject performSelector:withObject:withObject:] + 84
27 UIKit 0x01d8016a -[UIApplication sendAction:to:from:forEvent:] + 118
28 UIKit 0x01d800e9 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
29 UIKit 0x01f1e19f -[UIControl sendAction:to:forEvent:] + 79
30 UIKit 0x01f1e51f -[UIControl _sendActionsForEvents:withEvent:] + 408
31 UIKit 0x01f1d525 -[UIControl touchesEnded:withEvent:] + 714
32 UIKit 0x022efeaa _UIGestureRecognizerUpdate + 12763
33 UIKit 0x01dfabdf -[UIWindow _sendGesturesForEvent:] + 1559
34 UIKit 0x01dfc298 -[UIWindow sendEvent:] + 1137
35 UIKit 0x01da1efb -[UIApplication sendEvent:] + 266
36 UIKit 0x01d77cb6 _UIApplicationHandleEventQueue + 7802
37 CoreFoundation 0x00d49d1f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
38 CoreFoundation 0x00d3f9ab __CFRunLoopDoSources0 + 523
39 CoreFoundation 0x00d3edc8 __CFRunLoopRun + 1032
40 CoreFoundation 0x00d3e706 CFRunLoopRunSpecific + 470
41 CoreFoundation 0x00d3e51b CFRunLoopRunInMode + 123
42 GraphicsServices 0x058c0664 GSEventRunModal + 192
43 GraphicsServices 0x058c04a1 GSEventRun + 104
44 UIKit 0x01d7e1eb UIApplicationMain + 160
45 Halo 0x0011eb6c main + 140
46 libdyld.dylib 0x03ceca21 start + 1
47 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The stack is not very helpful to me and I can't even figure out the opening message: "insertObject:atIndex:]: index 2 beyond bounds [0 .. 0]." No where in this sample and my test with a single table entry should there be an index of '2.' Any help you could provide would be appreciated.
Here's my 'bt' on this exception:
* thread #1: tid = 0xc9ca7, 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x0401969a libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x03fe4634 libsystem_pthread.dylib`pthread_kill + 101
frame #2: 0x03d9339d libsystem_c.dylib`abort + 156
frame #3: 0x04034ae7 libc++abi.dylib`abort_message + 151
frame #4: 0x04055683 libc++abi.dylib`default_terminate_handler() + 300
frame #5: 0x032360b6 libobjc.A.dylib`_objc_terminate() + 108
frame #6: 0x04052d0d libc++abi.dylib`std::__terminate(void (*)()) + 14
frame #7: 0x0405293e libc++abi.dylib`__cxa_rethrow + 103
frame #8: 0x03235fad libobjc.A.dylib`objc_exception_rethrow + 47
frame #9: 0x00d3e7d0 CoreFoundation`CFRunLoopRunSpecific + 672
frame #10: 0x00d3e51b CoreFoundation`CFRunLoopRunInMode + 123
frame #11: 0x058c0664 GraphicsServices`GSEventRunModal + 192
frame #12: 0x058c04a1 GraphicsServices`GSEventRun + 104
frame #13: 0x01d7e1eb UIKit`UIApplicationMain + 160
* frame #14: 0x0011eb6c Halo`main + 140 at AppDelegate.swift:26
frame #15: 0x03ceca21 libdyld.dylib`start + 1
Per request, here's the code followed by the output:
// Retrieve Current Table View and Animate Changes
let tableView = self.superview!.superview as! UITableView
// Test Output
print( "tableView.numberOfSections: \(tableView.numberOfSections)" )
print( "tableView.numberOfRowsInSection( sender.tag ): \(tableView.numberOfRowsInSection( sender.tag ))" )
// Reload Section with Animation
tableView.reloadSections(NSIndexSet( index: sender.tag ), withRowAnimation: animation )
tableView.numberOfSections: 1
tableView.numberOfRowsInSection( sender.tag ): 1
This section of the stack trace (probably) means that you have an IBOutletCollection, and UIKit is now trying to populate it from a storyboard or nib:
7 UIKit 0x024f4d4f -[UIRuntimeOutletCollectionConnection performConnect] + 964
8 UIKit 0x024f4daf -[UIRuntimeOutletCollectionConnection connect] + 33
And this section looks like it’s trying to add bound objects to an existing array:
2 CoreFoundation 0x00cdd211 -[__NSArrayM insertObject:atIndex:] + 881
3 Foundation 0x01510134 -[NSKeyValueSlowMutableArray insertObject:atIndex:] + 115
4 CoreFoundation 0x00d38630 -[NSMutableArray insertObjects:count:atIndex:] + 192
5 CoreFoundation 0x00d38322 -[NSMutableArray insertObjectsFromArray:range:atIndex:] + 322
6 CoreFoundation 0x00d381c2 -[NSMutableArray addObjectsFromArray:] + 834
All of that means that the error may not have anything to do with the code you posted, but rather with your nib and how it interacts with the properties it’s bound to.
Take a look at whether you’re using an IBOutletCollection, and if so, start debugging the things it’s bound to.
I have an iOS app that has been working quite well in two languages – I know added some stuff, already keeping in mind using NSLocalizedString for localization etc. The english version of the app works fine so far, but the second language version crashes right after starting. Why?
One should note that I have not added all NSLocalizedStrings in my localizable.strings file. Furthermore, I have two separate Storyboards for both english an german. Any help would be greatly appreciated!
2014-12-18 18:14:36.083 Coverdale[48297:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x002461e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x020538e5 objc_exception_throw + 44
2 CoreFoundation 0x001fa8b2 -[__NSArrayI objectAtIndex:] + 210
3 UIKit 0x0126a35f -[UITableViewDataSource tableView:indentationLevelForRowAtIndexPath:] + 127
4 UIKit 0x00fe3f34 -[UITableViewController tableView:indentationLevelForRowAtIndexPath:] + 61
5 UIKit 0x00e012cf __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 1786
6 UIKit 0x00d7581f +[UIView(Animation) performWithoutAnimation:] + 82
7 UIKit 0x00d75868 +[UIView(Animation) _performWithoutAnimation:] + 40
8 UIKit 0x00e00bd0 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
9 UIKit 0x00e0813d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
10 UIKit 0x00e081f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
11 UIKit 0x00de9ece -[UITableView _updateVisibleCellsNow:] + 2428
12 UIKit 0x00dfe6a5 -[UITableView layoutSubviews] + 213
13 UIKit 0x00d7e964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x0206582b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x007c845a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x007bc244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x007bc0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18 QuartzCore 0x007227fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
19 QuartzCore 0x00723b85 _ZN2CA11Transaction6commitEv + 393
20 QuartzCore 0x00724258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
21 CoreFoundation 0x0020e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
22 CoreFoundation 0x0020e2bf __CFRunLoopDoObservers + 399
23 CoreFoundation 0x001ec254 __CFRunLoopRun + 1076
24 CoreFoundation 0x001eb9d3 CFRunLoopRunSpecific + 467
25 CoreFoundation 0x001eb7eb CFRunLoopRunInMode + 123
26 GraphicsServices 0x0406b5ee GSEventRunModal + 192
27 GraphicsServices 0x0406b42b GSEventRun + 104
28 UIKit 0x00d0ff9b UIApplicationMain + 1225
29 Coverdale 0x0009b95d main + 141
30 libdyld.dylib 0x028b9701 start + 1
31 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
EDIT
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"Error";
if (indexPath.section == 0) {
if(indexPath.row == 0)
{ /*..*/}
}
return cell;
}
Turns out I needed to implement indentationLevelForRowAtIndexPath and just return 0.
i have problem when i try delete or add object a the list
errror:
2014-09-04 10:59:03.815 DeleteListTest[2781:60b] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:1368
2014-09-04 10:59:03.856 DeleteListTest[2781:60b] *** 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 (9) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(
0 CoreFoundation 0x01b581e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018d78e5 objc_exception_throw + 44
2 CoreFoundation 0x01b58048 +[NSException raise:format:arguments:] + 136
3 Foundation 0x014b74de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x0066ff63 -[UITableView _endCellAnimationsWithContext:] + 13402
5 UIKit 0x0067fcea -[UITableView endUpdatesWithContext:] + 51
6 UIKit 0x0067fd18 -[UITableView endUpdates] + 41
7 DeleteListTest 0x00002ece -[MasterViewController leaveEditMode] + 270
8 DeleteListTest 0x0000301a -[MasterViewController tableView:commitEditingStyle:forRowAtIndexPath:] + 202
9 UIKit 0x006916a3 -[UITableView animateDeletionOfRowWithCell:] + 107
10 UIKit 0x0081a595 -[UITableViewCell _swipeDeleteButtonPushed] + 70
11 libobjc.A.dylib 0x018e9880 -[NSObject performSelector:withObject:withObject:] + 77
12 UIKit 0x005993b9 -[UIApplication sendAction:to:from:forEvent:] + 108
13 UIKit 0x00599345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
14 UIKit 0x0069abd1 -[UIControl sendAction:to:forEvent:] + 66
15 UIKit 0x0069afc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
16 UIKit 0x0069a243 -[UIControl touchesEnded:withEvent:] + 641
17 UIKit 0x0092f2e3 _UIGestureRecognizerUpdate + 7166
18 UIKit 0x005d8a5a -[UIWindow _sendGesturesForEvent:] + 1291
19 UIKit 0x005d9971 -[UIWindow sendEvent:] + 1021
20 UIKit 0x005ab5f2 -[UIApplication sendEvent:] + 242
21 UIKit 0x00595353 _UIApplicationHandleEventQueue + 11455
22 CoreFoundation 0x01ae177f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
23 CoreFoundation 0x01ae110b __CFRunLoopDoSources0 + 235
24 CoreFoundation 0x01afe1ae __CFRunLoopRun + 910
25 CoreFoundation 0x01afd9d3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x01afd7eb CFRunLoopRunInMode + 123
27 GraphicsServices 0x03a0a5ee GSEventRunModal + 192
28 GraphicsServices 0x03a0a42b GSEventRun + 104
29 UIKit 0x00597f9b UIApplicationMain + 1225
30 DeleteListTest 0x00004a4d main + 141
31 libdyld.dylib 0x0219f701 start + 1
32 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
this is the delete method
if(editingStyle == UITableViewCellEditingStyleDelete){
[tableTitles removeObjectAtIndex:[indexPath row]];
[self leaveEditMode];
[[self tableView] reloadData];
someone can help me ? thx u :)
I believe you are missing the call to:
[self.tableView deleteRowsAtIndexPaths:indexPath
withRowAnimation:UITableViewRowAnimationFade];
and you don't need the reloadData call:
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableTitles removeObjectAtIndex:[indexPath row]];
[self.tableView deleteRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self leaveEditMode];
(this will also look better as it will give visual feedback to the user; unlike reloadData).
This question already has an answer here:
insertObject: atIndex: - index 3 beyond bounds for empty array
(1 answer)
Closed 8 years ago.
I'm getting this crash. Here is my crash reason. I didn't understand what I am doing.
reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x036131e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02c1c8e5 objc_exception_throw + 44
2 CoreFoundation 0x035b43f6 -[__NSArrayM objectAtIndex:] + 246
3 Stampd 0x0007e928 -[VenueProfile tableView:cellForRowAtIndexPath:] + 472
4 UIKit 0x017c811f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
5 UIKit 0x017c81f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
6 UIKit 0x017a9ece -[UITableView _updateVisibleCellsNow:] + 2428
7 UIKit 0x017be6a5 -[UITableView layoutSubviews] + 213
8 UIKit 0x0173e964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
9 libobjc.A.dylib 0x02c2e82b -[NSObject performSelector:withObject:] + 70
10 QuartzCore 0x0055945a -[CALayer layoutSublayers] + 148
11 QuartzCore 0x0054d244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x0054d0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
13 QuartzCore 0x004b37fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
14 QuartzCore 0x004b4b85 _ZN2CA11Transaction6commitEv + 393
15 QuartzCore 0x00581cc6 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 474
16 QuartzCore 0x00582147 _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
17 CoreFoundation 0x035d1ac6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
18 CoreFoundation 0x035d14ad __CFRunLoopDoTimer + 1181
19 CoreFoundation 0x035b9538 __CFRunLoopRun + 1816
20 CoreFoundation 0x035b89d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x035b87eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x03bdb5ee GSEventRunModal + 192
23 GraphicsServices 0x03bdb42b GSEventRun + 104
24 UIKit 0x016cff9b UIApplicationMain + 1225
25 Stampd 0x000044e2 main + 130
26 libdyld.dylib 0x0431d701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The error
[__NSArrayM objectAtIndex:]: index 2 beyond bounds for empty array
clearly states that, trying to access the empty array. Check the array as alloc & init and has objects in it
Put your array in NSLog at the method numberOfRowsInSection. This will give you objects in the array and if array is empty please check if you initialize your array properly. If not, alloc and init your array before adding objects into it.