簡體   English   中英

調整大小后,iOS Table視圖單元格無法正確顯示

[英]iOS Table view cell not displaying properly after resize

我已經用6個靜態單元格設置了表格視圖,並且嘗試在選擇時擴展一個單元格(第三個單元格)。 問題是,它在調用reloadRowsAtIndexPaths:之后會調整大小,但隨后該單元格將顯示為空白。 如果我將單元格滾動到視線之外,它將正確顯示內容。

當我調用[tableView reloadData] ,單元格不是空白,但隨后我就無法欣賞動畫了。

有誰知道為什么會這樣嗎?

好吧,如果您設置行的高度,那么您需要重新加載單元格的內容,而不是整個表格的內容。 如果調用[tableview reloadData],則僅表示您重繪了整個表格(不進行高度校正)。

要重新加載表中的單個單元格:

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates]; 

我不知道我是唯一一個有空白靜態單元問題的人。 我偶然發現了一個解決方案,它在調用reloadRowsAtIndexPaths:之后調用了[tableView reloadData] reloadRowsAtIndexPaths:

  • 使用主線程重新加載相應的表格視圖行。

[[NSOperationQueue mainQueue] addOperationWithBlock:^ {

  // Reload the respective table view row using the main thread. [self.tblFiles reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; }]; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM