码迷,mamicode.com
首页 > 移动开发 > 详细

IOS UI基础09

时间:2015-08-10 00:14:57      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

  • 数据更新
    • 全局刷新
   #pragma mark - 数据刷新操作
- (IBAction)add {
    // 添加模型数据
    JXWine *wine = [[JXWine alloc] init];
    wine.money = @"20.5";
    wine.name = @"很好喝的酒";
    wine.image = @"new_wine";
    [self.wineArray insertObject:wine atIndex:0];
    //    [self.wineArray addObject:wine];

    // 告诉tableView:模型数据改变了,赶紧刷新表格
    [self.tableView reloadData];
}

- (IBAction)remove {
    // 删除模型数据
    [self.wineArray removeObjectAtIndex:0];
    [self.wineArray removeObjectAtIndex:0];

    // 告诉tableView:模型数据改变了,赶紧刷新表格
    [self.tableView reloadData];
}

- (IBAction)update {
//    JXWineCell *cell = (JXWineCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
//    cell.detailTextLabel.text = @"¥100";

    // 更改模型数据
    JXWine *wine = self.wineArray[0];
    wine.money = @"100";

    JXWine *wine2 = self.wineArray[1];
    wine2.name = @"哈哈";

    // 告诉tableView:模型数据改变了,赶紧刷新表格
    [self.tableView reloadData];
}
  • 局部刷新
   #pragma mark - 数据刷新操作
- (IBAction)add {
    // 添加模型数据
    JXWine *wine = [[JXWine alloc] init];
    wine.money = @"20.5";
    wine.name = @"很好喝的酒";
    wine.image = @"new_wine";
    [self.wineArray insertObject:wine atIndex:0];

    JXWine *wine2 = [[JXWine 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];
}

- (IBAction)remove {
    // 删除模型数据
    [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];
}

- (IBAction)update {
    // 更改模型数据
    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];
}

IOS UI基础09

标签:

原文地址:http://www.cnblogs.com/liujiaoxian/p/4716724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!