在其中一個視圖中有一個UITableView,它會經常更新。 跟蹤更改,可使用「reloadRowsAtIndexPaths」以經典的方式完成保持所選單元格重載reloadRowsAtIndexPaths UITableView
-(void)refreshCells:(NSArray *)changedCells
{
NSLog(@"refreshCells %i",[changedCells count]);
[TableView beginUpdates];
[TableView reloadRowsAtIndexPaths:changedCells withRowAnimation:UITableViewRowAnimationBottom];
[TableView endUpdates];
}
問:我怎樣才能保護用戶最後選擇的小區。每次更新refreshCells後單元格的位置可能會改變?
Afaik reloadRowsAtIndexPaths僅爲'changedCells'中的每個索引路徑調用delegate cellForRowAtIndexPath,因此單元格數保持不變,因此索引路徑保持不變。如果當然由於某種原因你改變了cellForRowAtIndexPath的返回順序,只有你可以知道選中的單元格的位置^^ – Tobi
我也有這個問題。我正在使用'reloadRowsAtIndexPaths:withRowAnimation:'來重新加載一個單元格。爲什麼取消選擇該單元格?這似乎是iOS SDK的一個錯誤。否則,該方法應該被調用:'reloadAndDeselectRowsAtIndexPaths:withRowAnimation:'。 – ma11hew28