加载远程数据的最佳方式
我目前正在开发一款 iPhone 应用程序,需要您的意见。
首先,我正在为足球俱乐部开发它。它包含许多选项卡(至少是这些):
- 新闻(显然,我在其中显示最后发布的新闻)
- 商店(用户可以在其中购买体育场座位,也许还有各种好东西)
- 尚不清楚(但它会相关) Facebook/Twitter 或类似的东西)
对于每个选项卡,我都需要下载 XML 数据(使用 initWithContentOfURL
)。正确的。但是,这就是我的问题所在。我应该:
- 在应用程序启动时加载每个需要的 xml 页面,并显示一个漂亮的加载屏幕?
- 在用户需要应用程序的瞬间加载每个需要的 xml 页面?
在第一种情况下,我的应用程序启动速度较慢,但选项卡之间的导航速度较快。
在第二种情况下,我的应用程序启动相对较快(仍然需要加载 News XML,即欢迎选项卡),但选项卡之间的切换不会像第一种情况那样流畅(当然,只有第一次打开选项卡时) )。
有什么建议吗?
I'm currently developping an iPhone app and need your opinion.
First, I am developping it for a Football (soccer) Club. It contains many tabs (at least these ones) :
- News (Where I am displaying last news posted, obviously)
- Shop (Where the user can buy stadium seats, and maybe various goodies)
- Don't know yet exactly (But it will be related to Facebook/Twitter or stuff like that)
For every of theses tabs, I need to download XML data (using initWithContentOfURL
). Right. But, that's where my problem is. Should I :
- Load every needed xml pages at application start-up, and display a nice loading screen ?
- Load every needed xml pages at the exact instant the user needs it in the application ?
In the first case, I get a slower application startup, but then, a faster navigation between tabs.
In the second case, my application starts relatively faster (still needs to load News XML, that's the welcome tab), but switching between tabs won't be as fluent as the first case (only the first time the tab is opened, of course).
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 ASIHttpRequest 它确实为您提供了一些可能合适并且通常可以使您满意的预构建缓存机制更轻松地与 Web 服务交互
Take a look at ASIHttpRequest which does provide some pre built caching mechanisms for you that may be appropriate and generally make interacting with web services easier
仅在需要时加载您需要的内容。
此外,我不会使用 initWithContentsOfUrl。这是一个同步调用,它将锁定您的应用程序。相反,使用 NSURLConnection 异步获取数据。
Load only what you need when you need it.
Furthermore, I wouldn't use initWithContentsOfUrl. It's a synchronous call, and it will lock your app. Instead, use an NSURLConnection to get the data asynchronously.