我有这样的代码。当我用异常断点进行调试时,它会在我reloadRow
时崩溃。UITableview reloadRowsAtIndexPaths和崩溃
- (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];
}];
}
我在我的单元格中使用约束,我所有的数据都是真的正确。我正在尝试阅读错误信息并在这里找到,但我不明白。请好好解释我应该怎么做。我完全不明白为什么它说
“的原因: '*** - [__ NSArrayM objectAtIndex:]:指数4超出范围[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
)
我认为这意味着你正在尝试重新加载第4行,但你的'UITableView'中只有3行。 –
这是可能的,但我从“cellForRowAtIndexPath”直接得到indexPath。为什么我有3排,我想重新加载第4排? –
'numberOfRowsInSection'怎么样? – nynohu