情況
在一個清單中
模拟資料狀态改變後
使用
reloadRowsAtIndexPaths:withRowAnimation:
來重新整理
cell
結果狀态改變
始終不盡人意!
無盡地測試
方法
reloadRowsAtIndexPaths:withRowAnimation:
的部分官方解釋:
Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.
度娘翻譯:
重新加載行會導緻表視圖向其資料源請求該行的新單元格。該表将新單元格動畫化,同時将舊行動畫化。如果要通知使用者單元格的值正在更改,請調用此方法。但是,如果通知使用者并不重要,也就是說,您隻想更改單元格顯示的值,就可以擷取特定行的單元格并設定其新值。
原因
方法
reloadRowsAtIndexPaths:withRowAnimation:
會導緻的問題是
當
cell
的數量不夠時
會建立新的
cell
是以
你以為你重新整理的
是原來的那一行
結果
系統給你傳回了一個新的!
視圖的狀态都是新的