Created
August 11, 2012 11:14
-
-
Save tatsuro-ueda/3323878 to your computer and use it in GitHub Desktop.
【XMLパーサ】【スレッド】XMLのパース進捗状況をプログレスバーで表示するには
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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> | |
 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment