使用stringWithContentsofurl时更新UI [英] Update UI when using stringWithContentsofurl

查看:155
本文介绍了使用stringWithContentsofurl时更新UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用stringWithcontentsofurl从Web服务器下载一些字符串到App,但是我想更新UI来显示某种类型的加载器。我正在下载一些字符串(有时可能会高达100个字符),因此用户显示的内容会很整齐,这样他们知道应用程序没有崩溃,因为现在UI被卡住了,我无法显示一个UILoader或类似的东西。有这样做的选择吗?或者也可以是stringWithcontentsofurl的替代方案,这是可能的?

I am using stringWithcontentsofurl to download some strings from my web server to the App, but i would like to update the UI to show A loader of some kind. I am downloading a number of strings (it can be sometimes as much as 100) so it would be neat for the user to show something so they know the App isn't crashing, because now the UI is stuck, i can't show A UILoader or something like that. Is there an option to do so? Or maybe A alternative to stringWithcontentsofurl where this is possible?

greets,
Erik

greets, Erik

推荐答案

这是Lazy Loading的经典案例。请参阅Apple的示例代码:

This is a classic case for "Lazy Loading". See Apple's example code:

http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html

它在您阅读该代码时,应该很容易将字符串替换为图像。

It should be easy to substitute "strings" for "images" as you read that code.

您希望在标签中显示占位符,如(获取信息)或类似的,然后在后台加载信息,或者使用自动获取(异步获取)线程或使用类似ASIHTTPRequest的库来处理所有异步的螺母和螺栓,一旦获取完成,调用委托方法。

You want to display a placeholder in the label like "(fetching information)" or similar and then load the information in the background, either threading the fetches yourself (asynchronous fetching) or using a library like ASIHTTPRequest that handles all the asynchronous nuts and bolts for you, calling a delegate method once the fetch has completed.

这篇关于使用stringWithContentsofurl时更新UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆