Adding items to UIScrollView to the Top
This is what I have.
I have a scrollView which I have filled up with dynamically with UIViews items from top to bottom sorted by a date value. I also added a UIRefreshControl to my scrollView for a "pull to refresh function".
So when the user does a 'pull to refresh' old items will will be added to the top of the scrollView. For this what i've done is I'm iterating through the subViews in my scrollView and pushing them down by reapplying the frame.
Ok, what I'm asking is that,is there any better way to do this?
I really can't imagine having to iterate through hundreds or even thousands of Views and pushing them down one by one.
There are lots of other ways and I should say efficient way to do this. I am giving suggestions as per my least to the best choice.
Way 1. What I assume is you probably having a view array in which you make a loop and taking the view out, adding frame (by dynamically calculating its Y position) and making it subview of scrollView. What you need to do is when you get a new one add that view at index 0 of that array, then reload your scrollview again.
Way 2 (which I will prefer): Replace your scroll view with Tableview or collection view. These are more efficient, memory managed and resource managed controls given by Apple. Every time you get a new view, add it to its first index and reload table or collection view.
P.S : Collection view is not available below 1OS 6.0.
I would suggest to go with option 2 as with option 1 you have to face many other issues like memory crash or performance issues.