ios - heightForRowAtIndexPath 从未被称为 iOS9

标签 ios uitableview heightforrowatindexpath

好吧,我很确定这个方法一直在为我的 UITableViewController 执行到现在。我的方法中有这样的打印语句:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //455(PERFECT MIN HEIGHT) 475 is perfect spacing. 15.5 is the scalar for when descriptionLabel expands lines
    return 475;
    NSLog(@"ISSSS ITTT ONNNN???");

    if (currentDescriptionHeight == 16.0) {
        NSLog(@"OHHH so it triggered 1111");
        return 475;
    }else if (currentDescriptionHeight == 31.5){
        NSLog(@"OHHH so it triggered 2222");
        return 490.5;
    }else if (currentDescriptionHeight == 47){
        NSLog(@"OHHH so it triggered 3333");
        return 506;
    }

    //475 - 1 line description,
}

我已将方法 header 复制到我的 .h 文件中,并已正确设置委托(delegate):

self.tableView.delegate = self;
self.tableView.dataSource = self;

在我的 viewDidLoad: 方法中。为什么我的 heightForRowAtIndexPath 根本没有被调用?

最佳答案

您只需要将函数顶部的 return 语句移动到底部或将其作为当前 if 语句的一部分放在 else 中,因为 return 语句会立即结束函数,因此它下面的代码将永远不会执行。

关于ios - heightForRowAtIndexPath 从未被称为 iOS9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33226917/

相关文章:

ios - 内部 Apple Watch 应用程序开发和部署?

ios - 在 didSelectRowAtIndexPath 中更改自定义 UIImage

UITableViewAutomaticDimension 未在 UITableviewCell 的 UILabel 中使用表情符号字符设置正确的高度

iOS - 动态调整 uitableviewcell 的问题

ios - 访问 heightForRowAtIndexPath 中的自定义单元格属性

ios - 具有不同 NSMutableParagraphStyle 的 Nsattributedstring

ios - 使 UIButton 图像和文本都可点击

ios - 从不同线程使用时 NSDateFormatter 崩溃

ios - 如何使用代码将 UITableView 放在 UILabel 下方

ios - 父/子和一对一/多逆向关系之间的核心数据差异