【发布时间】:2013-07-28 15:57:59
【问题描述】:
我很难弄清楚为什么我的 UITableViewCell 在未选中时不会为 contentView 设置动画。
我编写了一些代码来展开和折叠单元格,但不知何故,当折叠单元格时,它会为高度设置动画,而不是 contentView。其实好像 contentView 被移除了。
作为记录,我在 contentView 中添加了一个 UILabel。展开时,UILabel 的框架会相应地调整大小,但在折叠时,UILabel 只是被解除或隐藏而没有动画。
有什么建议吗?
这里是一些示例代码:
/* Expanding and collapsing code */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self cellIsSelected:indexPath])
{
//Item is clicked, unclick it
[self.selectedIndexes removeObject:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
else
{
//Item is not clicked. Deselect others and select this
[self.selectedIndexes removeAllObjects];
[self.selectedIndexes addObject:indexPath];
}
[tableView beginUpdates];
[tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self cellIsSelected:indexPath]) {
return 150;
}
return [tableView rowHeight];
}
【问题讨论】:
标签: uikit core-animation uitableview