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_ACCESSACCESS错误的缘由:

    • 当你没因此实现**estimatedHeightForRowAtIndexPath方法,在heightForRowAtIndexPath办法获得cell的下,会形成一个死循环,那即便是numberOfRowsInSectionheightForRowAtIndexPath方不断互调,最后程序崩溃.

相关文章