viewDidLoad后加载数据

发布于 10-26 11:39 字数 272 浏览 11 评论 0原文

我有一个 viewController,它要求我加载一系列图像并将它们显示在屏幕上,但是在 viewDidLoad 中加载这些图像需要一段时间,并且在视图出现在屏幕上之前存在延迟。

有没有一种方法可以让我在 viewDidLoad 中只加载屏幕上可见的前 5 个图像,然后在 viewController 加载后立即加载剩余的图像?

这是 viewWillAppear 或 viewDidAppear 的用途吗? 是否有其他地方最适合用于加载内容而不延迟用户的响应时间?

非常感谢!

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 for the users?

Thanks so much in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

芯好空2024-11-02 11:39:43

您可以使用 viewWillAppear 来显示前 5 个图像/数据,而不会对用户造成任何延迟,并在 viewDidAppear 中显示剩余数据。

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

手心的温暖2024-11-02 11:39:43

如果您只想在加载图像之前显示视图,您当然可以在 viewDidAppear 中执行此操作。请记住,viewDidAppear 可能会被多次调用,并且您可能只想加载图像。

如果您从互联网下载图像(即加载时间较长),您可能需要实现一个图像加载器,让您的控制器知道图像已准备好通过委托显示。如果所有图像都存储在本地并在几秒钟内加载,则 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.

尘世孤行2024-11-02 11:39:43

我建议您使用 GCD 或 NSInspiration 在后台线程上加载图像。在 viewDidLoad 中,您只需启动后台处理。将图像加载到后台线程后,将它们传递到主线程并按您的意愿显示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文