ios - 在带有静态单元格的 UITableView 中使用 reloadSection 时动画出现故障

标签 ios animation uitableview

我正在为我的应用程序的设置 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 之外再返回,它看起来又正常了。

编辑:对问题进行了一些截图:
Example Image

我尝试在 reloadSections 之前和之后添加 beginUpdatesendUpdates 但它没有改变任何东西。使用 reloadData 而不是 reloadSections 可以工作,但根本没有动画。

是因为表格的单元格是静态的还是我遗漏了什么?

最佳答案

我觉得这个方法应该可以解决你的问题。

[self.tableView insertSections:<#(NSIndexSet *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];

只需更新数据源(您不必这样做,因为您正在根据某些标志更新部分计数)并调用它。

也许你必须改用这种方法。

[self.tableView insertRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>];

关于ios - 在带有静态单元格的 UITableView 中使用 reloadSection 时动画出现故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14256800/

相关文章:

ios - 在 iOS 6 中调整大小后 MKMapView 变为空白

iphone - 核心数据关系、NSPredicates 和 NSFetchedResultsController

iPhone MapKit 是否可以从一系列触摸中映射坐标?

ios - 向Realm托管对象添加字符串列表会导致应用在启动时崩溃

c# - WPF - Storyboard 完成事件

javascript - 什么样的CSS3动画是异步的?

android - 按钮按下动画更长

ios - 如何将目标操作添加到 UITableViewCell

ios - 带有 SWRevealViewController 的 Exc_bad_instruction

ios - 如何单击位于 UITableView 下方的按钮