情况:
在我的应用程序的某处,我开始从我的服务器下载数据。在下载开始之前,我想更新一个UILabel来说@“Now Downloading ...”。下载结束后将其设置为空白。
问题:
似乎下载占用了所有计算机的注意力,UILabel永远不会更新,直到最后(下载已经结束)等等被设置为空白(或实时永远不可见)。
问题:
如何在下载之前简单地更新我的UILabel说“正在下载”?
答案 0 :(得分:3)
label.text = @"Downloading";
NSOperationQueue *operationQueue = [[NSOperationQueue]alloc]init];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(download) object:@"http://www.google.com"];
[operationQueue addOperation:operation];
[operation release];
- (void)download:(NSString *)url
{
// do the download
[self performSelectorOnMainThread:@selector(didFinishDownload) withObject:nil waitUntilDone:NO];
}
- (void)didFinishDownload
{
label.text = @"";
}
答案 1 :(得分:0)
如果您使用NSURLRequest
- > NSURLConnection
和NSURLConnection的委托方法,它将在后台执行下载,并将通知代理传入的数据。这也可以让您显示进度。