[英]Reload specific UITableView cell in iOS
我有一個UITableView
。 我想根據所做的選擇更新表數據。 現在我使用[mytable reloadData]
; 我想知道是否有任何方法可以更新所選的特定單元格。 我可以使用 NSIndexPath 或其他方式進行修改嗎? 有什么建議么?
謝謝。
對於 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 object 的引用並更改其標簽等。
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"Hey, I've changed!";
我認為您正在尋找UITableView
的這種方法:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.