NSXMLParser parserDidStartDocument冻结应用程序

时间:2012-12-11 14:35:38

标签: ios xml parsing refresh freeze

我试图在调用后添加一些操作

- (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];}

1 个答案:

答案 0 :(得分:1)

希望这会对你有所帮助

- (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);


}