亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否可以刷新UITableView中的單個UITableViewCell?

是否可以刷新UITableView中的單個UITableViewCell?

侃侃無極 2019-11-06 10:17:06
我有一個UITableView使用UITableViewCells 的自定義。每個UITableViewCell按鈕都有2個按鈕。單擊這些按鈕將更改UIImageView單元格中的圖像。是否可以分別刷新每個單元以顯示新圖像?任何幫助表示贊賞。
查看完整描述

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]; 

當然,您可以設置任何喜歡的動畫效果。


查看完整回答
反對 回復 2019-11-06
?
守著星空守著你

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];

}


查看完整回答
反對 回復 2019-11-06
?
吃雞游戲

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)

{

    ....

}


查看完整回答
反對 回復 2019-11-06
  • 3 回答
  • 0 關注
  • 748 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號