我正在使用dispatch_async在一个合适的视图中解析xml数据这里是我的代码:
- (void) Parse{
dispatch_async( dispatch_get_global_queue(0, 0), ^{
NSString *post =[[NSString alloc] initWithFormat:@"http://messages.xml"];
NSData *xmlData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:post]];
xmlParserObject =[[NSXMLParser alloc]initWithData:xmlData];
[xmlParserObject setDelegate:self];
dispatch_async( dispatch_get_main_queue(), ^{
[xmlParserObject parse];
});
});
[messageList reloadData];
}
现在uitableview没有显示任何数据。它在dispatch_async
之前完美运行答案 0 :(得分:1)
我认为您的代码存在问题。请在dispatch_get_main_queue()
- (void) Parse {
dispatch_async( dispatch_get_global_queue(0, 0), ^{
NSString *post =[[NSString alloc] initWithFormat:@"http://messages.xml"];
NSData *xmlData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:post]];
xmlParserObject =[[NSXMLParser alloc]initWithData:xmlData];
[xmlParserObject setDelegate:self];
[xmlParserObject parse];
dispatch_async( dispatch_get_main_queue(), ^{
[messageList reloadData];
});
});
}