Before the table update, my table datasource has only one section with one row:
After the update the data source returns two more sections, each with only one row:
I use the following code to animate the table update:
// 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();
However, only section 1 and its row are animated. Section 2 (with row [2,0]) appears instantly and does not move/fade a bit. I also checked with "Slow Animations" toggled.
What is wrong with this code?
Edit: I forgot to mention, the problem exists also if I omit the InsertRows
call, which is unnecessary according Sam's answer.
Found out why: I was creating a new UITableViewSource
instance every time UpdateTable()
was invoked. This went all fine and well, except for some details when animating the changing of the table sections and rows.
When I changed the code to reuse the UITableViewSource
instance, everything worked as expected.
When inserting a section you do not need to animate individual rows. Just call insert section code. Also, similarly when removing a section you do not need to remove rows within.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.