When I’m getting new data from my server I need to:
- update existing data for the existing rows of
UITableViewand - insert new rows with animation.
The thing is I don’t know when [UITableView reloadData] is finished for step 1,
so I can start step 2.
How to deal with this situation?
I prefer to use step 1 with [UITableView reloadData] for simplicity, but any other solution to achieve both steps in one logic step will be cool too.
UPDATE – maybe this is my mistake.
it’s seems that
-update data model with existing rows info
-reloadData
-update data model with new rows info
-insertWorsAtIndexPaths
works O.K now.
I removed some “ugly” way that force main thread to refresh after step 1, and for now, everything is O.K
(the “ugly way was calling [NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.0f] , that for some reason I need to add it to work in the past)
Wonder..if everything really O.K now.
Will Update if somthing still wrong.
Sorry for the troubles 🙂
update 2
this is how now I use it and seems to work ok :
-update existing rows in data model, then call
[UITableView reloadData];
-add new rows to data model, then call
[UITableView beginUpdates]
[UITableView insertRowsAtIndexPath withRowAnimation]
[UITableView endUpdates]
You could use
reloadSections:withRowAnimation:to update your rows with an animation. Or you can usereloadDatatheninsertRowsAtIndexPaths:withRowAnimation:it depends how do you get the data.Check the UITableView Reference