我正在为我的应用程序的设置 View 使用带有静态单元格的 UITableView
。
此表的一个部分包含两个单元格,第二个单元格仅在第一个单元格中包含的 UISwitch
打开时可见。
所以 UISwitch
的目标是这样的:
- (void)notificationSwitchChanged:(id)sender
{
UISwitch* switch = (UISwitch*)sender;
self.bNotify = switch.on;
[self.settingsTable reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
我以这种方式实现了 numberOfRowsInSection:
:
(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
if (section != 1)
return [super tableView:tableView numberOfRowsInSection:section];
if (self.bNotify)
return 2;
return 1;
}
这“有效”,但动画有问题,使第一个单元格消失或向上滑动到前一节下方的一半或各种东西,具体取决于我选择的动画类型。最干净的是 UITableViewRowAnimationNone
,但仍不完美。
如果我将该部分滚动到 View 之外再返回,它看起来又正常了。
编辑:对问题进行了一些截图:
我尝试在 reloadSections
之前和之后添加 beginUpdates
和 endUpdates
但它没有改变任何东西。使用 reloadData
而不是 reloadSections
可以工作,但根本没有动画。
是因为表格的单元格是静态的还是我遗漏了什么?
最佳答案
我觉得这个方法应该可以解决你的问题。
[self.tableView insertSections:<#(NSIndexSet *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];
只需更新数据源(您不必这样做,因为您正在根据某些标志更新部分计数)并调用它。
也许你必须改用这种方法。
[self.tableView insertRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];
关于ios - 在带有静态单元格的 UITableView 中使用 reloadSection 时动画出现故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14256800/