3 回答
TA貢獻1811條經(jīng)驗 獲得超6個贊
有了單元格的indexPath后,您可以執(zhí)行以下操作:
[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];
當(dāng)然,您可以設(shè)置任何喜歡的動畫效果。
TA貢獻1799條經(jīng)驗 獲得超8個贊
我嘗試僅致電-[UITableView cellForRowAtIndexPath:],但是沒有用。但是,以下示例對我有用。我alloc和release該NSArray用于緊密內(nèi)存管理。
- (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條經(jīng)驗 獲得超7個贊
reloadRowsAtIndexPaths:很好,但是仍然會迫使UITableViewDelegate方法觸發(fā)。
我能想到的最簡單的方法是:
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
[self configureCell:cell forIndexPath:indexPath];
這是重要的調(diào)用你configureCell:的主線程中執(zhí)行,如在非UI線程它不會工作(同樣的故事reloadData/ reloadRowsAtIndexPaths:)。有時添加以下內(nèi)容可能會有所幫助:
dispatch_async(dispatch_get_main_queue(), ^
{
[self configureCell:cell forIndexPath:indexPath];
});
還有必要避免在當(dāng)前可見視圖之外進行的工作:
BOOL cellIsVisible = [[self.tableView indexPathsForVisibleRows] indexOfObject:indexPath] != NSNotFound;
if (cellIsVisible)
{
....
}
- 3 回答
- 0 關(guān)注
- 749 瀏覽
添加回答
舉報
