不,你不必同時使用兩者。您可以使用reloadCell
技術或通過beginUpdate
和endUpdate
更新單元格。
當您重新加載特定行時,內部表格視圖系統會創建2個單元格,然後與新單元格進行混合。您可以刪除beginUpdates
和endUpdates
,只需調用它即可更改高度。但動畫不會平滑,您將觀察小細胞的線條,同時從較大的細胞高度動畫回來。
至於beginUpdates
和endUpdates
他們用於組插入,刪除等,但它是一個古老的黑客強制調用表視圖委託,並獲得選定的索引更改後的高度。這種技術很好地處理高度變化動畫。所以,你的代碼會像
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Write the code to track the selected index path.
tableView.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.Automatic)
}
OR
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates]; // tell the table you're about to start making changes
//Write the code to track the selected index path.
[tableView endUpdates]; // tell the table you're done making your changes
}
這不是 「一個或另一個」。它們被用於不同的目的。 'beginUpdates()'和'endUpdates()'用於將插入,刪除等分組在一起,以便同時進行動畫處理。他們實際上沒有修改任何東西。但是如果你已經閱讀過[documentation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/beginUpdates),那就應該是明確。 –
感謝您的迴應!我以前在有關由beingUpdates和endUpdates方法定義的動畫塊中調用reloadRowsAtIndexPaths的文檔中閱讀了一些內容。並看看在stackoverflow類似的線程,這兩個解決方案已被推薦爲我想要完成的。這就是爲什麼我有點困惑。對不起,如果問題看起來很懶,但在閱讀文檔後我真的很想找一點解釋。 – user3353890