UITableView动画头痛

bpa*_*anj 2 iphone view objective-c uitableview nsarray

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];
Run Code Online (Sandbox Code Playgroud)

上面的代码工作,它动画.问题是我有很多数据,我不想硬编码行索引.由于我的表中只有一个部分可以为0.如何动态生成NSIndexPath对象的NSArray?

或者是否有更简单的方法来为表格视图设置动画.当用户单击表视图顶部的选项卡时,表视图中的所有行都会更改.

drv*_*ijk 7

要生成索引路径数组,您可以循环:

    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];
Run Code Online (Sandbox Code Playgroud)

如果重新加载TableView中的所有数据,为什么不调用reloadData方法呢?

  • reloadData没有动画. (3认同)

ccj*_*sen 6

如果要刷新整个部分:

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
Run Code Online (Sandbox Code Playgroud)