开发者

How add activity indictor with parsing?

I want to add activity indicator or MBProgressHUD when i click on row of table view and disapear when next view's table laod.

- (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 Er开发者_运维知识库rors");
        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];
}

} above code is for selecting row.In when this function call then view add activity indicator or MBProgressHUD and release in next view. How do that?


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

set activity.hidden = TRUE; in viewwillAppear.


iRam11,
Just implement this code and ask if you have any problem.
NextView.h
Declare

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜