【发布时间】:2011-08-12 13:26:18
【问题描述】:
我有一个UITableView。我想根据所做的选择更新表数据。现在我使用[mytable reloadData];我想知道是否有任何方法可以更新所选的特定单元格。我可以使用 NSIndexPath 或其他方式进行修改吗?有什么建议吗?
谢谢。
【问题讨论】:
标签: iphone ios uitableview
我有一个UITableView。我想根据所做的选择更新表数据。现在我使用[mytable reloadData];我想知道是否有任何方法可以更新所选的特定单元格。我可以使用 NSIndexPath 或其他方式进行修改吗?有什么建议吗?
谢谢。
【问题讨论】:
标签: iphone ios uitableview
对于 iOS 3.0 及以上版本,您只需调用:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
例如,要重新加载第 2 节的第 3 行和第 3 节的第 4 行,您必须这样做:
// Build the two index paths
NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:3 inSection:2];
NSIndexPath* indexPath2 = [NSIndexPath indexPathForRow:4 inSection:3];
// Add them in an index path array
NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, indexPath2, nil];
// Launch reload for the two index path
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
【讨论】:
您还可以获取对 UITableViewCell 对象的引用并更改其标签等。
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"Hey, I've changed!";
【讨论】:
我想你正在寻找UITableView的这种方法:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
【讨论】: