在你的项目中把estimatedHeightForRowAtIndexPath方法写实现以下,返回一个估计高度(随便估,笔者建议还是按照正常思路来写,大概高度是多少就返回多少),这样就不会报EXC_BAD_ACCESS错误了.

注意:estimatedHeightForRowAtIndexPath方法既是下面这个方法.

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath;

知识拓展:

  • 在没有实现estimatedHeightForRowAtIndexPath方法时,这三个方法(numberOfRowsInSection,heightForRowAtIndexPath,cellForRowAtIndexPath)的调用顺序如下:
    • 1.先调用numberOfRowsInSection
    • 2.再调用heightForRowAtIndexPath
    • 3.再调用cellForRowAtIndexPath
  • 实现了estimatedHeightForRowAtIndexPath方法后,调用顺序是这样的

    • 1.numberOfRowsInSection
    • 2.estimatedHeightForRowAtIndexPath
    • 3.cellForRowAtIndexPath
    • 4.heightForRowAtIndexPath
  • 接下来我来说明以下出现EXC_BAD_ACCESS错误的原因:

    • 当你没用实现**estimatedHeightForRowAtIndexPath方法,在heightForRowAtIndexPath方法获取cell的时候,会形成一个死循环,那就是numberOfRowsInSectionheightForRowAtIndexPath方法不断互调,最后程序崩溃.

相关文章:

  • 2021-09-30
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-14
  • 2022-01-18
  • 2022-12-23
  • 2022-02-26
  • 2022-01-09
相关资源
相似解决方案