Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tatsuro-ueda/3323878 to your computer and use it in GitHub Desktop.
Save tatsuro-ueda/3323878 to your computer and use it in GitHub Desktop.
【XMLパーサ】【スレッド】XMLのパース進捗状況をプログレスバーで表示するには
##Setting progress of ProgressView while parsing XML
First, count the number of lines.
NSError *error = nil;
NSString *xmlFileString = [NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding error:&error];
_totalLines = [xmlFileString componentsSeparatedByString:@"\n"].count;
Then, catch the progress in delegate method block. For example:
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
[self.elementStack addObject:elementName];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[mainQueue addOperationWithBlock:^{
_progressView.progress = (CGFloat)[parser lineNumber] / (CGFloat)_totalLines;
}];
}
Sample Project is Here:
<https://github.com/weed/p120727_XMLParseProgress>
![ss](http://farm9.staticflickr.com/8433/7758147164_1bdc0fb3b3_o.png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment