表更新之前的一個,我的表數據源中只有一個部分有一行:的UITableView InsertRows(insertRowsAtIndexPaths)僅動畫兩個部分
- 第0
- 行[0,0]
更新後數據源返回兩個以上的部分,每個僅具有一個列:
- 第0
- 行[0,0]
- 第一節
- 行[1,0]
- 第2節
- 行[2,1 0]
我用下面的代碼進行動畫處理的表更新:
// update the table data source, without reloading the table UpdateTable(); TableView.BeginUpdates(); // insert sections 1 and 2 TableView.InsertSections(NSIndexSet.FromNSRange(new NSRange(1, 2)), UITableViewRowAnimation.Fade); // insert two new rows, one for each new section (rows [1,0] and [2,0]) TableView.InsertRows(new NSIndexPath[] { NSIndexPath.FromRowSection(0, 1), NSIndexPath.FromRowSection(0, 2) }, UITableViewRowAnimation.Fade); TableView.EndUpdates();
但是,只有第1節和其行的動畫。第2部分(帶行[2,0])立即出現,不會移動/淡入一點。我還檢查了「慢動畫」切換。
這段代碼有什麼問題?
編輯:我忘了提及,如果我省略了InsertRows
調用,根據Sam的回答,這是不必要的。
當我在ViewDidAppear事件執行的4個部分的測試視圖+表視圖上嘗試此代碼時,出現以下錯誤:NSInternalInconsistencyException原因:無效的更新:部分的無效數目。更新後的表視圖中包含的節數(4)必須等於更新前的表視圖中包含的節數(4),加上或減去插入或刪除的節數(插入2個,0刪除)。 – callisto 2013-02-21 10:40:12