“正在加载”弹出/进度条

时间:2011-01-07 18:15:05

标签: iphone objective-c multithreading download loading

嗨:)
我正在开发一个iPhone应用程序,它应该从Web加载XML页面并使用它做一些事情。问题是应用程序在下载页面时会冻结,看起来很难看 我想用旋转轮显示某种“正在加载,请”的消息...
什么是正确的方法?
我尝试使用NSThread,但收到此错误:

Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread.

这是我用来加载XML页面的obj-C代码:

NSString* xmlUrl = [NSString stringWithFormat:@"http://urltothexmlpage"];
NSString* XML = [NSString stringWithContentsOfURL:[NSURL URLWithString:xmlUrl]
                                         encoding:NSUTF8StringEncoding
                                            error:nil];

2 个答案:

答案 0 :(得分:2)

我不知道你的应用程序的细节,但最好的方案是执行xml的异步请求。让用户等待永远不是一件好事。您可以使用ASIHTTPRequest来处理请求,因为它是一个非常易于使用的框架。检查“Creating an asynchronous request”部分。

答案 1 :(得分:1)

查看MBProgressHUD以了解加载屏幕。