如何在分配XML文件时放置进度条

时间:2013-11-25 10:13:53

标签: ios xml xml-parsing progress-bar

我完成了解析xml文件的问题是如何在解析xml文件时放置进度条。进度条的进度应根据解析的xml文件的数量来计算,我该如何实现。 请帮帮我

这是我解析xml文件的方式

- (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];
}

0 个答案:

没有答案