【发布时间】:2015-03-31 07:40:18
【问题描述】:
这就是我想要做的。
我有一个UITableViewCell,可以说固定高度为 300(它实际上是一个可变大小的高度,但我试图简化示例)
我想要实现的是,当我向上滚动时 - 我将有一个“缩略图”版本的单元格 - 高度为 75
我设法做到了,但现在的问题是,当我向上滚动时,之前的单元格高度会被调整,一旦单元格尺寸变小,滚动位置就会“跳跃”,这会导致视图“向下跳跃”当他向上滚动时。
如何调整?
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (indexPath.row < lastViewedChapter)
{
cell = [self generateChapterCell:tableView indexPath:indexPath collapsed:YES];
}
else
{
cell = [self generateChapterCell:tableView indexPath:indexPath collapsed:NO];
if (indexPath.row > lastViewedChapter)
{
lastViewedChapter = indexPath.row;
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row < lastViewedChapter)
{
return 73;
}
else
{
return 300; //actually here is a code that calculates the height
}
}
【问题讨论】:
-
这是一段时间以来我在 SO 上看到的最酷的东西之一。因此,当您说视图“跳回”时,您的意思是 tableview 的内容,即单元格突然向上跳?因为那是我认为应该发生的事情。
-
我认为我们在谈论同样的事情。当您向上滚动时,您会到达可见单元格的边缘,然后重新生成顶部单元格,导致滚动返回到可见单元格中间的某个位置。用户体验真的很差——怎么办?
-
我操纵了委托函数来获得你需要的东西。检查一下,让我知道它是否适合你。
标签: ios uitableview