In continuation to my question asked here, i want to know if the method to update the UI in viewDidScroll is correct. As i can observe the method is called many times and probably may be the reason why the ui become jittery and unresponsive. How can i increase the responsiveness of the UI. The code is as below:
BOOL isScrollingDown = verticalScrollView.contentOffset.y > _previousContentOffsetY;
_previousContentOffsetY = verticalScrollView.contentOffset.y;
CGFloat pageHeight = verticalScrollView.frame.size.height;
int scrollingToPageNum = isScrollingDown ? (ceil((verticalScrollView.contentOffset.y - pageHeight) / pageHeight) + 1) : (floor((verticalScrollView.contentOffset.y - pageHeight) / pageHeight) + 1);
int page = floor((verticalScrollView.contentOffset.y - pageHeight / 2) / pageHeight) + 1;
[self loadPage:(page-1)];
[self loadPage:(page)];
[self loadPage:(page+1)];
/* Unloading the pages not seen in the view is done here*/
if (!(isScrollingDown) && scrollingToPageNum >1) {
[self unloadPages:page-2];
}else {
[self unloadPages:page+2];
}
The lazy loading technique works fine and lot of memory usage is reduced due to it. However the UI is too slow. Also i want to know how to update the UI from a different thread which downloads image from a URL.
TIA, Praveen