zoukankan      html  css  js  c++  java
  • 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方法不断互调,最后程序崩溃.
  • 相关阅读:
    HDU
    HDU
    (4)数据--相似性与相异性
    (3)数据--操作
    (2)数据--基本概念
    五、按生命周期划分数据(二)
    五、常用数据类型(一)
    四、坏耦合的原因与解耦(三)
    四、强化耦合(二)
    四、初识耦合(一)
  • 原文地址:https://www.cnblogs.com/rglmuselily/p/7918571.html
Copyright © 2011-2022 走看看