我有一个视图,当我单击一个按钮时,我使用 TBXML 解析器从 XML 文件中获取一些内容。在单击按钮方法中看起来像这样:
// Should be [activityIndicator startAnimating];
NSURL *url = [NSURL URLWithString:@"adress.xml"];
NSData *data = [NSData dataWithContentsOfURL:url];
TBXML *tbxml = [TBXML newTBXMLWithXMLData:data error:nil];
listArray = [NSMutableArray arrayWithObjects:nil];
[self getData:tbxml.rootXMLElement];
// Should be [activityIndicator stopAnimating];
但是activityIndicator不显示......这不是它的实现问题,因为如果我在视图的开头添加它就会看到它......所以我被卡住了。有什么建议吗?
非常感谢
编辑:这是代码:
我的函数,当我单击按钮时调用:
NSURL *url = [NSURL URLWithString:@"adress.xml"];
dispatch_queue_t queue = dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSData *data = [NSData dataWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^(void) {
TBXML *tbxml = [TBXML newTBXMLWithXMLData:data error:nil];
listArray = [NSMutableArray arrayWithObjects:nil];
[self getData:tbxml.rootXMLElement];
[activityIndicator stopAnimating];
});
});
我的 getData 函数:
- (void) getData : (TBXMLElement *) element
{
Offre *offre = [[Offre alloc] init];
do {
if(!go) if([[TBXML elementName:element] isEqualToString:@"item"]) go = YES;
if(go)
{
if([[TBXML elementName:element] isEqualToString:@"title"]) [offre set_title:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"description"]) [offre set_description:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"pubDate"]) [offre set_pubDate:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"link"]) [offre set_link:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"contract-type"]) [offre set_contractType:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"salary"]) [offre set_salary:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"fn-org"]) [offre set_fnOrg:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"locality"]) [offre set_locality:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"state"]) [offre set_state:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"filiere"]) [offre set_filiere:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"categorie"]) [offre set_categorie:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"statut"]) [offre set_statut:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"country-name"]) [offre set_countryName:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"tag"]) [offre set_tag:[TBXML textForElement:element]];
if([[TBXML elementName:element] isEqualToString:@"familleMetiers"])
{
[offre set_familleMetier:[TBXML textForElement:element]];
[listArray addObject:offre];
offre = nil;
}
}
if (element->firstChild) [self getData:element->firstChild];
} while ((element = element->nextSibling));
}
我想知道这是否不是因为函数的递归性。