【发布时间】:2016-08-05 08:52:22
【问题描述】:
我正在heightForRowAtIndexPath- 中以编程方式计算单元格的高度
我的完整方法是:
- (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 没有加载。
当使用此代码应用程序返回高度时工作正常:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 100;
}
我不知道这是这条线的问题:
id cell = [self.tableView dequeueReusableCellWithIdentifier:kCellID];
我在这个问题中缺少什么?
【问题讨论】:
-
@Anbu.Karthik 我需要找到单元格的类型,因为我有两种类型的单元格。这是主要问题。每当我使用代码查找单元格类型时,我的应用就会开始延迟
-
为什么不使用属性 isTableViewWithCustomCells 或 isTableViewWithOtherCustomCells?它应该更快。我认为
heightForRowAtIndexPath:可能会在 cellForRowAtIndexPath 和出列的东西之前被调用。 -
有时
heightForRowAtIndexPath在 cellForRowAtIndexPath 之前调用然后呢?
标签: ios objective-c uitableview ios8