3 回答
TA貢獻1811條經驗 獲得超6個贊
有了單元格的indexPath后,您可以執行以下操作:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPathOfYourCell, nil] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
在Xcode 4.6和更高版本中:
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:@[indexPathOfYourCell] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
當然,您可以設置任何喜歡的動畫效果。
TA貢獻1799條經驗 獲得超8個贊
我嘗試僅致電-[UITableView cellForRowAtIndexPath:],但是沒有用。但是,以下示例對我有用。我alloc和release該NSArray用于緊密內存管理。
- (void)reloadRow0Section0 {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *indexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[indexPaths release];
}
TA貢獻1829條經驗 獲得超7個贊
reloadRowsAtIndexPaths:很好,但是仍然會迫使UITableViewDelegate方法觸發。
我能想到的最簡單的方法是:
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
[self configureCell:cell forIndexPath:indexPath];
這是重要的調用你configureCell:的主線程中執行,如在非UI線程它不會工作(同樣的故事reloadData/ reloadRowsAtIndexPaths:)。有時添加以下內容可能會有所幫助:
dispatch_async(dispatch_get_main_queue(), ^
{
[self configureCell:cell forIndexPath:indexPath];
});
還有必要避免在當前可見視圖之外進行的工作:
BOOL cellIsVisible = [[self.tableView indexPathsForVisibleRows] indexOfObject:indexPath] != NSNotFound;
if (cellIsVisible)
{
....
}
- 3 回答
- 0 關注
- 748 瀏覽
添加回答
舉報
