如何通过解析添加活动指示器?

时间:2011-08-25 12:42:47

标签: iphone parsing uitableview uiactivityindicatorview mbprogresshud

当我点击表格视图的行时,我想添加活动指示符或MBProgressHUD,当下一个视图的表格显示时,我想删除它。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) {
    /*here add activity indiavtor*/

    iMapViewAppDelegate *appDelegate = (iMapViewAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *requestString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/xml?origin=%@&destination=%@,OK&sensor=false",startField.text,endField.text]; 
    NSURL *url = [[NSURL alloc] initWithString:requestString];
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];

    //Initialize the delegate.
    xml1 *parser = [[xml1 alloc] init];

    //Set delegate
    [xmlParser setDelegate:parser];


    //Start parsing the XML file.
    BOOL success = [xmlParser parse];


    if(success){
        NSLog(@"No Errors");
        appDelegate.legAray=[parser.listofPoint copy];
        appDelegate.sAray=[parser.ListofSteps1 copy];
        arySteps=[[NSArray alloc]init];
        arySteps = [parser.ListofSteps1 arrayByAddingObjectsFromArray:parser.listofPoint];
        appDelegate.NoofRow=0;
        appDelegate.NoofRow=[arySteps count];
        NSLog(@"%d",appDelegate.NoofRow);
        NSLog(@"%@",arySteps);
        sObject=[[Sleg alloc]init];
        sObject=[appDelegate.legAray objectAtIndex:0];

    }
    else
        NSLog(@"Error Error Error!!!");


        controller= [TableView alloc];
        controller.arayStep=[arySteps copy];
        [controller initWithNibName:@"TableView" bundle:nil];
        [self.navigationController pushViewController:controller animated:YES];
        [controller release];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

}  上面的代码用于选择row。在此函数调用时,然后查看添加活动指示符或MBProgressHUD并在下一个视图中释放。怎么样?

2 个答案:

答案 0 :(得分:1)

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) 
{

    chkIndexPath = indexPath.row;    
    activity.hidden = FALSE;
    [activity startAnimating];

    [self performSelector:@selector(myFunction) withObject:nil afterDelay:0.0];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)myFunction
{
  //your code. use chkIndexPath instead of indexPath.row
}

activity.hidden = TRUE;中设置viewwillAppear

答案 1 :(得分:1)

iRam11,
只需实施此代码并询问您是否有任何问题 NextView.h
声明

UIAlertView *av;
UIActivityIndicatorView *actIndicator;

NextView.m

in viewWillAppear call this callWebService Method

-(void)callWebService {
av = [[UIAlertView alloc] initWithTitle:@"Loading..." message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
actIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
[actIndicator setFrame:CGRectMake(120, 70, 40, 40)];
[actIndicator setHidesWhenStopped:YES];
[av addSubview:actIndicator];
[actIndicator startAnimating];
[av show];
[av release];


//Do you web service call
}

-(void)parserDidEndDocument:(NSXMLParser *)parser {
    // Do you tableview reload.
    [av dismissWithClickedButtonIndex:0 animated:YES];
    actIndicator.hidden = YES;
}