objective-c - UITableView 动画令人头疼

标签 objective-c iphone uitableview view 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];

上面的代码可以工作并且有动画效果。问题是我有很多数据,我不想对行索引进行硬编码。由于我的表部分中只有一个部分可以为 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/

相关文章:

objective-c - Objective-C : App getting Memory Warning Level 2 and exits shortly after

html - Safari 视口(viewport)错误,固定位置和底部或顶部的问题

iphone - 在 UITableViewController 代码中的 UITableView 后面添加 UIView

ios - 在 UITableViewCell 上触摸按钮后如何隐藏 UIBarButtonItem

objective-c - ObjectiveC 项目中的 SwiftUI - 列表在预览中工作,而不是在运行时工作

iphone - 如何从 UIImage 获取透明区域?

ios - 无法访问 Sprite 的用户数据属性

iphone - 检查 bundle 中是否存在图像 - iPhone

objective-c - 从横向旋转到纵向后 UITableView 的奇怪行为 (iPad)

ios - UITableView 空 View 放不下