我尝试在通话后添加一些操作
- (void)parserDidStartDocument:(NSXMLParser *)parser {
//NSLog(@"found file and started parsing");
alertView = [[UIAlertView alloc] initWithTitle:@"Caricamento..."
message:@"\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alertView addSubview:spinner];
[spinner startAnimating];
[alertView show];
}
但是它冻结了应用程序一段时间,然后在完成XML解析后,加载AlertView ecc。与UIRefreshControl相同。我向下滑动tableView,解析时应用程序冻结,我看不到微调器旋转。
任何想法?
编辑:
在这里,我第一次调用解析器:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString * path = @"thexmlpath.xml";
if(!caricato)
[NSThread detachNewThreadSelector:@selector(parseXMLFileAtURL:) toTarget:self withObject:path];
//[self parseXMLFileAtURL:path];
caricato = YES;}
我在使用RefreshControl时在这里打电话:
- (void)refreshControlRequest{
NSLog(@"refreshing...");
NSString * path = @"thexmlpath.xml";
[self performSelector:@selector(parseXMLFileAtURL:) withObject:path];}
最佳答案
希望对你有帮助
- (void)parserDidStartDocument:(NSXMLParser *)parser {
//NSLog(@"found file and started parsing");
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_async(queue, ^{
alertView = [[UIAlertView alloc] initWithTitle:@"Caricamento..."
message:@"\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alertView addSubview:spinner];
[spinner startAnimating];
[alertView show];
});
dispatch_release(queue);
}