【发布时间】:2014-04-11 19:57:11
【问题描述】:
在带有动画 (UITableViewRowAnimationTop) 的 UITableView 中插入/删除 UITableViewCell 时,我看到了一种奇怪的效果。
当要插入的单元格比上面的单元格大得多时,就会出现动画故障。
This video 显示模拟器中的故障,黄色单元格在它应该从顶部滑动时突然出现。
Here 是视频中的 Xcode 项目。
下面是单元格插入/动画代码。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2 + self.thirdCellVisible;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (indexPath.row == 1)
{
if (self.thirdCellVisible)
{
self.thirdCellVisible = !self.thirdCellVisible;
[tableView deleteRowsAtIndexPaths:@[self.thirdCellIndexPath]
withRowAnimation:UITableViewRowAnimationTop];
}
else
{
self.thirdCellVisible = !self.thirdCellVisible;
[tableView insertRowsAtIndexPaths:@[self.thirdCellIndexPath]
withRowAnimation:UITableViewRowAnimationTop];
}
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == self.thirdCellIndexPath.row)
{
return 100.0f;
}
return 44.0f;
}
【问题讨论】:
-
该项目的链接显然已被删除。你能把它放回去吗?
-
@Sheamus 您可以轻松地在代码中重新生成。尝试在 UITableView 中插入一个具有动态行的单元格。
-
@Nicholas :您必须分别在调用插入/删除方法之前和之后调用
[tableView beginUpdates]和[tableView endUpdates]。 -
@kidsid49:我的答案如下。
标签: ios uitableview animation