Invalid row height provided by table delegate. Value must be greater than zero or UITableViewAuto...

项目开发久了,有的时候会出现一些莫名其妙的错误,这个错误分析可以任务,单元格的高度大于零或者是设置自适应高度,具体错误信息如下:

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
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 下班路上有一家烘焙面包店,每每经过的时候,总是有一簇簇、一团团的浓郁香气扑过来,让自己得费很大力气才能控制住自己“...
    药山阅读 781评论 0 51
  • 因为饱受 GFM 和 Redcarpet 两种 Markdown 引擎生成 TOC 链接的差异的折磨,而我又不得不...
    闷骚的程序员阅读 632评论 0 0
  • 家里的小楼房终于装出点头绪了 妈妈说,马上搬到新家,见面就不容易了……当时觉得妈妈很萌。 妈妈看着我初有型的小蛮腰...
    风筝飞飞阅读 325评论 0 0
  • 手动设定IP、DNS只需要修改三个文件就可以了 1、/etc/sysconfig/network $ vi /et...
    TOUCH_KING阅读 1,051评论 0 0
  • 亲爱的悬河: 从认识到爱你,就是初入到大学到系际辩论赛的时间,情不知所起,却一往而深。 面试的时候,黄队说她选择这...
    鱼隅阅读 258评论 1 1