NSIndexPath* updatedPath = [NSIndexPath indexPathForRow: 0 inSection: 0];
NSIndexPath* updatedPath2 = [NSIndexPath indexPathForRow: 1 inSection: 0];
NSArray* updatedPaths = [NSArray arrayWithObjects:updatedPath, updatedPath2, nil];
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];
上面的代码可以工作并且有动画效果。问题是我有很多数据,我不想对行索引进行硬编码。由于我的表部分中只有一个部分可以为 0。如何动态生成 NSIndexPath 对象的 NSArray?
或者是否有更简单的方法来为表格 View 设置动画。当用户单击 TableView 顶部的选项卡时, TableView 中的所有行都会发生变化。
最佳答案
要生成索引路径数组,您可以循环:
NSMutableArray *updatedPaths = [NSMutableArray array];
for (NSNumber *row in someArray) {
NSIndexPath *updatedPath = [NSIndexPath indexPathForRow:[row intValue] inSection:0];
[updatedPaths addObject:updatedPath];
}
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];
如果重新加载 TableView 中的所有数据,为什么不直接调用 reloadData 方法呢?
关于objective-c - UITableView 动画令人头疼,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1096967/