首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查找UITableViewCell高度时出现问题

查找UITableViewCell高度时出现问题
EN

Stack Overflow用户
提问于 2016-08-05 16:52:23
回答 2查看 69关注 0票数 0

我用heightForRowAtIndexPath-编程计算单元格的高度

我的完整方法是:

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id cell = [self.tableView dequeueReusableCellWithIdentifier:kCellID];

    if([cell isKindOfClass:[Custom class]])
    {
        return 100;
    }
    else
    {
         return 20;
    }
}

我的应用需要3-5秒来显示ViewController。虽然调用了cellForRowAtIndexPath,但我可以在控制台中显示日志。

但是我的ViewController没有加载。

当只返回高度时,使用此代码应用程序可以很好地工作:

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 100;
}

我不知道这就是这行的问题所在:

代码语言:javascript
复制
id cell = [self.tableView dequeueReusableCellWithIdentifier:kCellID];

我在这一期中遗漏了什么?

EN

回答 2

Stack Overflow用户

发布于 2016-08-05 21:03:38

cellForRowAtIndexPath:方法中有一些逻辑,用于确定该行应该是哪种类型的单元格。将该逻辑添加到heightForRowAtIndexPath:方法中,以确定每行的高度。

票数 0
EN

Stack Overflow用户

发布于 2017-01-12 17:37:35

你的这行是错的

代码语言:javascript
复制
id cell = [self.tableView dequeueReusableCellWithIdentifier:kCellID];

它会迫使你的细胞重复使用。

使用

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id cell=[tableView cellForRowAtIndexPath:indexPath];

    if([cell isKindOfClass:[CustomCellClass class]])
    {
        return 100;
    }
    else
    {
         return 20;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38785116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档