Ios 解析XML文件时如何放置进度条
iam解析xml文件完成问题是如何在解析xml文件时放置progressbar。进度条的进度应该根据解析的xml文件的数量来计算,我如何才能做到这一点。 请帮帮我 这就是我解析xml文件的方式Ios 解析XML文件时如何放置进度条,ios,xml,xml-parsing,progress-bar,Ios,Xml,Xml Parsing,Progress Bar,iam解析xml文件完成问题是如何在解析xml文件时放置progressbar。进度条的进度应该根据解析的xml文件的数量来计算,我如何才能做到这一点。 请帮帮我 这就是我解析xml文件的方式 - (void)viewDidLoad { appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate]; data=[[NSMutableArray alloc]init]; dic_parsing=
- (void)viewDidLoad
{
appDelegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
data=[[NSMutableArray alloc]init];
dic_parsing=[[NSMutableDictionary alloc]init];
NSString *str_url1=[NSString stringWithFormat:@"%@type=getnews",APIURL];
API_call *apicall=[[API_call alloc]init];
apicall.delegate=self;
[apicall NSURLConnectionFunction:str_url1 :@"all"];
[apicall release];
// Do any additional setup after loading the view, typically from a nib.
[super viewDidLoad];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return[data count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[data objectAtIndex:indexPath.row];
NSLog(@"value==>%@",data);
return cell;
}
-(void)responestring:(NSData *)data :(NSString *)pagename{
[self parseXMLFileAtURL:data parseError:Nil];
}
-(void)failedresponse:(NSString *)pagename{
// [appDelegate alert_hidden];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser{
NSLog(@"XML Located.. Begin Parsing..");
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
NSLog(@"sirecamdata");
currentElement = [elementName copy];
if([elementName isEqualToString:@"get_news"]){
[dic_parsing removeAllObjects];
//category_update
}
}
-(NSString *)checknullvalues:(NSString *)strvalue{
if(strvalue==nil||[strvalue isEqualToString:@"(null)"]||[strvalue isEqualToString:NULL]){
return @"";
}else {
return strvalue;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
string=[self checknullvalues:string];
[dic_parsing setObject:string forKey:currentElement];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
////////////////////////////////////
if([elementName isEqualToString:@"get_news"]){
NSString *str=[dic_parsing objectForKey:@"title"];
NSLog(@"str==>%@",str);
}
}
-(void)progress
{
UIAlertView *myAlert1 = [[UIAlertView alloc]initWithTitle:@""
message:@"success"
delegate:self
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[myAlert1 show];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[NSTimer scheduledTimerWithTimeInterval:.75 target:self selector:@selector(progress) userInfo:nil repeats:NO];
}
如果不对文档进行两次解析,就无法知道您还剩下多少,但这是毫无意义的。只需显示一个活动微调器。感谢您的快速回放…您所说的“两次解析文档”是什么意思?如果您不知道还有多少元素,您怎么知道还有多少元素?你怎么知道有多少元素,除非你已经数过了?除非解析文档,否则如何计算它们?基本上,你不能做你想做的事。我看过这段代码,但我不明白错误*error=nil;NSString*xmlFileString=[NSString stringWithContentsOfURL:url编码:NSUTF8STRING编码错误:&错误]_TotalInes=[xmlFileString组件由字符串分隔:@“\n”]。计数`