• iOS之estimatedHeightForRowAtIndexPath避免程序EXC_BAD_ACCESS


    在你的项目中把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方法不断互调,最后程序崩溃.
  • 相关阅读:
    zookeeper的ACL权限控制
    Zookeeper客户端Curator基本API
    get和post的区别
    Html基本操作实例代码
    poj3322 Bloxorz I
    Delphi 调用SQL Server 2008存储过程
    架构设计师—你在哪层楼?
    LINUX常用命令
    分层自动化测试与传统自动化测试的差别
    商业智能漫谈
  • 原文地址:https://www.cnblogs.com/rglmuselily/p/7918571.html
Copyright © 2020-2023  润新知