我有一个从Web服务加载数据的小iPhone应用程序。为了确保在加载数据时没有任何问题,我通过应用程序创建了一个半透明视图,并使用CFRunloopRun()等待所有数据在后台加载。这是该代码:如何在后台加载数据时使用UI事件
self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
// Now show an animation
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
UIView *window = [[UIApplication sharedApplication] keyWindow];
UIView *shield = [[UIView alloc] initWithFrame:window.bounds];
shield.backgroundColor = [UIColor blackColor];
shield.alpha = 0.5f;
[window addSubview:shield];
spinner.center = shield.center;
[shield addSubview:spinner];
spinner.hidden = NO;
NSLog(@"JCL.callServerWithRequest(), spinner view: %@, shield view: %@, window: %@", spinner, shield, window);
[spinner startAnimating];
// Hand over to the Runnloop to wait
CFRunLoopRun();
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
[shield removeFromSuperview];
[shield release];
这工作得很好,只是一个按钮点击任何地方被加载后打得如此,如果用户点击下载按钮两次,他会做两次下载以及。
任何想法如何在屏蔽被移除之前消耗UI事件。
谢谢 - 安迪
什么视图是按钮? – MCannon 2011-03-19 01:57:23