#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];
}