0

我正在从 XML 文件加载大量数据。该数据正在“冻结”应用程序。我想在加载数据时显示进度条。

我怎么知道大部分操作已经完成,以便我可以更改进度条显示的百分比?谢谢。[已回答]

编辑:主要问题是由于要解析的大量数据,应用程序在加载过程中冻结。有些人建议使用后台线程来加载和解析数据。这可行吗?

4

2 回答 2

2

一次将文件读入内存@ 4k?显示加载字节与文件大小的过程?

另外找出总行数以及解析器所在的当前行。

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/Reference/Reference.html#//apple_ref/occ/instm/NSXMLParser/lineNumber

假设您正在使用 NSXMLParser

“冻结”来自您在主线程上进行加载/解析。如果您可以让我们 GCD 尝试执行 dispatch_async ( ) 并在完成时将更新发送到您的主线程并更新进度。

于 2012-05-15T15:49:11.230 回答
0

如果您使用的是 NSXML 解析器,

NSUInteger count = [[rootElement nodesForXPath:@"//Video" error:&error] count];
//this will give you the number of elements
//then after parsing each element, calculate the percentage of elements parsed. 

//i.e. num_of_elements_parsed/total_no_elements*100;
//based on this value, use a del;egate method to update your NSProgressIndicator 
// in this method increment the  num_of_elements_parsed counter
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {

    if ([elementName isEqualToString:@"resident"]) {

        self.count += 1; 

    }
}
于 2012-05-15T16:25:35.763 回答