我用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];我在这一期中遗漏了什么?
发布于 2016-08-05 21:03:38
cellForRowAtIndexPath:方法中有一些逻辑,用于确定该行应该是哪种类型的单元格。将该逻辑添加到heightForRowAtIndexPath:方法中,以确定每行的高度。
发布于 2017-01-12 17:37:35
你的这行是错的
id cell = [self.tableView dequeueReusableCellWithIdentifier:kCellID];它会迫使你的细胞重复使用。
使用
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
id cell=[tableView cellForRowAtIndexPath:indexPath];
if([cell isKindOfClass:[CustomCellClass class]])
{
return 100;
}
else
{
return 20;
}
}https://stackoverflow.com/questions/38785116
复制相似问题