您所在的位置:小祥子 » 编程 » IOS » 正文

UITableView数据刷新

时间:2015-07-24 编辑:啊啦大大 来源:Cnblogs

tableView数据刷新

UITableView 数据刷新,其实就是修改模型数据,然后刷新模型数据

UITavleView数据刷新

  • 增加模型 insertRowsAtIndexPaths: withRowAnimation:
// 添加模型数据
    XMGWine *wine = [[XMGWine alloc] init];
    wine.money = @"20.5";
    wine.name = @"很好喝的酒";
    wine.image = @"new_wine";
    [self.wineArray insertObject:wine atIndex:0];

    XMGWine *wine2 = [[XMGWine alloc] init];
    wine2.money = @"100.5";
    wine2.name = @"很好";
    wine2.image = @"new_wine";
    [self.wineArray insertObject:wine2 atIndex:0];

    // 刷新
    NSArray *indexPaths = @[
                            [NSIndexPath indexPathForRow:0 inSection:0],
                            [NSIndexPath indexPathForRow:1 inSection:0]
                            ];
    [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
- 删除模型数据 deleteRowsAtIndexPaths: withRowAnimation:
//  删除模型数据
    [self.wineArray removeObjectAtIndex:0];
    [self.wineArray removeObjectAtIndex:0];

    // 刷新
    NSArray *indexPaths = @[
                            [NSIndexPath indexPathForRow:0 inSection:0],
                            [NSIndexPath indexPathForRow:1 inSection:0]
                            ];
    [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationMiddle];
- 更改模型数据	reloadRowsAtIndexPaths: withRowAnimation:
   // 更改模型数据
    XMGWine *wine = self.wineArray[0];
    wine.money = @"100";

    XMGWine *wine2 = self.wineArray[2];
    wine2.image = @"new_wine";

    XMGWine *wine3 = self.wineArray[3];
    wine3.image = @"new_wine";

    // 局部刷新
    NSArray *indexPaths = @[
                            [NSIndexPath indexPathForRow:0 inSection:0],
                            [NSIndexPath indexPathForRow:2 inSection:0],
                            [NSIndexPath indexPathForRow:3 inSection:0]
                            ];
    [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationLeft];
- 强制刷新 [self.tableView reloadData];
关键词:Table 数据