问题描述
我最近已经从TBXML切换到RaptureXML,尽管提取信息要容易得多,但是当我点击包含xml表格视图的标签栏按钮时,会有明显的延迟.
I've recently switched from TBXML to RaptureXML, and even though pulling in information is much easier, there is a noticeable delay when I tap the tab bar button containing my xml table view.
在我的viewDidLoad方法中,我有以下内容"
In my viewDidLoad method I have the following"
events = [[NSMutableArray alloc] init];
[self loadURL];
我的loadURL方法如下:
And my loadURL method is the following:
- (void)loadURL {
RXMLElement *rootXML = [RXMLElement elementFromURL:[NSURL URLWithString:@"http://api.somexml.com/xml"]];
[rootXML iterateWithRootXPath:@"//event" usingBlock:^(RXMLElement *event) {
[events addObject:[NSArray arrayWithObjects:
[event attribute:@"uri"],
[event attribute:@"displayName"],
[event attribute:@"type"],
nil]];
}];
[rootXML iterateWithRootXPath:@"//location" usingBlock: ^(RXMLElement *location) {
[events addObject:[NSArray arrayWithObjects:
[location attribute:@"city"],
[location attribute:@"lat"],
[location attribute:@"lng"],
nil]];
}];
[rootXML iterateWithRootXPath:@"//start" usingBlock:^(RXMLElement *start) {
[events addObject:[NSArray arrayWithObjects:
[start attribute:@"time"],
[start attribute:@"date"],
nil]];
}];
}
我可以做些什么来加快速度吗?另外,当我将行数分配为[事件数]时,我应该只得到6时得到19行.
Is there something I can do to speed it up? Also when I assign my row count as [events count] I'm getting 19 rows when I should only get 6. Please help.
推荐答案
直到正确为止.您需要在后台线程上进行解析.请执行以下操作:
Till is on the right track. You need to parse on a background thread. Do something like the following:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self loadURL];
dispatch_async(dispatch_get_main_queue(), ^{
[tableView reloadData];
});
});
您会注意到我正在主线程上重新加载tableview.在后台线程上更新接口元素有点不可.
You'll notice that I'm reloading the tableview on the main thread. Updating interface elements on a background thread is a bit no-no.
这篇关于RaptureXML有点慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!