我有一个带有静态单元格的表格 View 。单击单元格可切换与此单元格关联的选择器 View 单元格的可见性(更改单元格高度)。单击单元格的 tag
属性维护选择器单元格的状态。动画由一系列 beginUpdates
、endUpdates
方法触发。这是为选择器单元格的可见性设置动画的简单方法(无需管理单元格插入和删除)。
#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat defaultHeight = [super tableView:tableView heightForRowAtIndexPath:indexPath];
switch (indexPath.row) {
case RowIndexDayTimePicker:
return self.dayTimeCell.tag > 0 ? defaultHeight : 0;
case RowIndexPrivacyPicker:
return self.privacyCell.tag > 0 ? defaultHeight : 0;
default:
return defaultHeight;
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case RowIndexDayTime:
self.dayTimeCell.tag *= -1;
self.privacyCell.tag = -1;
break;
case RowIndexPrivacy:
self.dayTimeCell.tag = -1;
self.privacyCell.tag *= -1;
break;
default:
break;
}
[tableView beginUpdates];
[tableView endUpdates];
}
动画按预期工作,直到我将 TableView 分隔符属性设置为 None
以使用自定义分隔符。比较两个屏幕截图(动画 gif):
我不知道如何修复它。我使用自动布局,选择器 View 与 super View 对齐,每边边距为零。在 iOS 7 模拟器和 iPos Touch 下测试。 Storyboard截图:
最佳答案
似乎是 UITableView 的错误。
怎么样:
self.tableView.separatorColor = [UIColor whiteColor]; //or clearColor?
或者:
self.tableView.separatorInset = UIEdgeInsetsMake(0, CGRectGetWidth(self.view.bounds), 0, 0);
(目标是隐藏而不是移除分隔符。)
关于ios - beginUpdates/endUpdates 后意外的表格单元格动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21403671/