在表更新之前,我的表数据源只有一个部分,一行:
- 第 0 节
- 第 [0,0] 行
更新后数据源返回另外两个部分,每个部分只有一行:
- 第 0 节
- 第 [0,0] 行
- 第 1 节
- 第 [1,0] 行
- 第 2 节
- 第 [2,0] 行
我使用以下代码来设置表格更新的动画:
// update the table data source, without reloading the table UpdateTable(); TableView.BeginUpdates(); // insert sections 1 and 2 TableView.InsertSections(NSIndexSet.FromNSRange(new NSRange(1, 2)), UITableViewRowAnimation.Fade); // insert two new rows, one for each new section (rows [1,0] and [2,0]) TableView.InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(0, 1), NSIndexPath.FromRowSection(0, 2) }, UITableViewRowAnimation.Fade); TableView.EndUpdates();
但是,只有第 1 部分及其行是动画的。第 2 部分(第 [2,0] 行)立即出现并且不会移动/淡出一点。我还检查了“慢速动画”切换。
这段代码有什么问题?
编辑: 我忘了说,如果我省略 InsertRows
调用,问题也存在,根据 Sam 的回答,这是不必要的。
最佳答案
找出原因:每次调用 UpdateTable()
时,我都会创建一个新的 UITableViewSource
实例。这一切都很好,除了在动画更改表格部分和行时的一些细节。
当我更改代码以重用 UITableViewSource
实例时,一切都按预期工作。
关于iphone - UITableView InsertRows (insertRowsAtIndexPaths) 仅对两个部分之一进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10352064/