项目开发久了,有的时候会出现一些莫名其妙的错误,这个错误分析可以任务,单元格的高度大于零或者是设置自适应高度,具体错误信息如下:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid row height provided by table delegate. Value must be greater than zero or UITableViewAutomaticDimension.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109859b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001092be141 objc_exception_throw + 48
2 CoreFoundation 0x000000010985dcf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000108e583b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000109f1c446 -[UITableView _classicHeightForRowAtIndexPath:] + 442
5 UIKit 0x0000000109f1c590 -[UITableView _heightForCell:atIndexPath:] + 166
6 UIKit 0x0000000109f09dbd __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 3284
7 UIKit 0x0000000109e5fd3e +[UIView(Animation) performWithoutAnimation:] + 90
8 UIKit 0x0000000109f090d0 -[UITableView _configureCellForDisplay:forIndexPath:] + 487
9 UIKit 0x0000000109f01b9e -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 410
10 8-UITabelViewDemo 0x0000000108cdc65f _TFC17__UITabelViewDemo14ViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 143
11 8-UITabelViewDemo 0x0000000108cdc707 _TToFC17__UITabelViewDemo14ViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 87
12 UIKit 0x0000000109f14762 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 750
13 UIKit 0x0000000109f149a8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
14 UIKit 0x0000000109ee92e9 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845
15 UIKit 0x0000000109f1d97c -[UITableView _performWithCachedTraitCollection:] + 111
16 UIKit 0x0000000109f04b2a -[UITableView layoutSubviews] + 233
17 UIKit 0x0000000109e6b20b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
18 QuartzCore 0x000000010ed82904 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x000000010ed76526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
20 QuartzCore 0x000000010ed763a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x000000010ed05e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
22 QuartzCore 0x000000010ed32130 _ZN2CA11Transaction6commitEv + 468
23 QuartzCore 0x000000010ed32b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
24 CoreFoundation 0x00000001097ff717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x00000001097ff687 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x00000001097e4038 CFRunLoopRunSpecific + 440
27 UIKit 0x0000000109da202f -[UIApplication _run] + 468
28 UIKit 0x0000000109da80d4 UIApplicationMain + 159
29 8-UITabelViewDemo 0x0000000108cdd9a7 main + 55
30 libdyld.dylib 0x000000010cf5865d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
一般来说没有人会把单元格的高度设置的小于零,应该是在计算的过程中出现问题:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50-100
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}