I have a UIPageControl that has 24 pages. Each page features a UITableView. A user can press buttons at the top of the screen to refresh the data (all 24 pages).
Calling reloadData on all pages causes a 3 second delay, but the data is refreshed and they can scroll through the UIPageControl and see fresh data. Calling reloadData on the current page is fast but only updates the page in question. When the user goes to the next page, the data is old/wrong.
My “fix” is to implement a system whereby I call reloadData on pages just before the user scrolls to them, one at a time, and keep track of which pages are fresh and which aren’t.
Is this the correct approach in a UIPageControl situation with a relatively large number of pages or am I misusing UIPageControl, using an incorrect way to refresh the pages, or something else.
I really appreciate your advice on fixing this performance issue.
Thanks.
I’m not sure that what you’re describing is a best practice, but I’m going to assume that you know what you’re doing and have figured out a workable solution (something not everyone here will assume).
I wasn’t quite sure based on your comment/question, but it seems like you’re already attempting to make an effort to only load data dynamically in a lazy fashion. If that’s the case, I likely have little to add, but here are a few ideas:
In the Apple UIPageControl example, each time the UIScrollView delegates calls its
scrollViewDidScroll:method, they load the current page, the previous page and the next page (handling, of course, for first and last page cases, where previous/next might not exist). Perhaps you could, in this method, call the[tableView reloadData].If you find you must load all 24 each time the page loads, perhaps you could call
[tableView reloadData]immediately and then iterate through the other pages, reloading their data one at a time, waiting for one page to complete before loading the next.Number 1 seems like an elegant way to have the data ready much more quickly.
Number 2 feels like a very kludgy hack to me, so I’d really try to see if number 1 would work.