开发者

Load data after viewDidLoad

开发者 https://www.devze.com 2023-02-19 19:16 出处:网络
I have a viewController that requires I load a whole series of images and display them on the screen, but loading those images in viewDidLoad takes a while and there is a delay before the view appears

I have a viewController that requires I load a whole series of images and display them on the screen, but loading those images in viewDidLoad takes a while and there is a delay before the view appears on screen.

Is there a way that I could load just the first 5 images that are visible on the screen in viewDidLoad, and then load the remaining images immediately after the viewController has loaded?

Is this what viewWillAppear or viewDidAppear are for? Is there somewhere else that is best used for loading content without delaying the response time fo开发者_运维问答r the users?

Thanks so much in advance!


you could use viewWillAppear to get first 5 images/data to display without any delay to user and rest data you could in viewDidAppear.


You could certainly do it in viewDidAppear, if you just want to show the view before loading the images. Keep in mind that viewDidAppear may be called more than once and you probably only want to load the images ones.

If you're downloading the images from the internet (i.e. long loading times), you might want to implement an image loader that will let you're controller know that the image is ready to be displayed through a delegate. If all the images are stored locally and load within seconds the viewDidAppear approach should work fine.


I would recommend you loading images on a background thread(s) either using GCD or NSInvocation. In viewDidLoad you'd just launch background processing. after images are loaded on a background thread, pass them to a main thread and display as you wish.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号