在iOS中重新加载特定的UITableView单元格

pa1*_*a12 23 iphone uitableview ios

我有一个UITableView.我想根据所做的选择更新表数据.现在我用[mytable reloadData]; 我想知道是否有任何方法可以更新所选的特定单元格.我可以使用NSIndexPath或其他方法进行修改吗?有什么建议?

谢谢.

Ced*_*rie 64

对于iOS 3.0及更高版本,您只需致电:

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
Run Code Online (Sandbox Code Playgroud)

例如,要重新加载第3部分的第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];
Run Code Online (Sandbox Code Playgroud)


Hol*_*nce 6

您还可以获取对UITableViewCell对象的引用并更改其标签等.

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"Hey, I've changed!";
Run Code Online (Sandbox Code Playgroud)