Question

I am a beginner in iOS programming. I am creating a tableview where, on click of each cell a different xml gets parsed. I want to show a activity indicator when xml is parsing and stop that indicator when parsing is finished. my code is,

//Activity Indicator //in viewDidLoad,

    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityIndicator.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
    activityIndicator.backgroundColor=[UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.5];
    activityIndicator.center=self.view.center;
    [activityIndicator startAnimating];
    [self.view addSubview:activityIndicator];

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell = [tableView cellForRowAtIndexPath:indexPath];
    if(cell.accessoryView==nil)
    {
        NSLog(@"index path is %i",indexPath.row+1);
        cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_selected.png"]];
        [myObj1 changecheckedvalue:1 forindex:[[tempArr objectAtIndex:indexPath.row]mainID]];

        if (indexPath.row==0)
        {
            flagToCheck=1;
            xmlName=@"Pournima";
            [parseArray removeAllObjects];
            [self xmlParsing];
        }
   }
}

How to achieve that? Please help.

Was it helpful?

Solution 2

Try using this one : https://github.com/jdg/MBProgressHUD It has a better look and feel.

Start the activity indicator before calling the method for parsing in "didSelectRowAtIndexPath" and stop it at the end of the method for parsing.

OTHER TIPS

You can use MBProgressHUD to display an activity view that sits on top the current view. The library is quite easy to use and implement. You would just import MBProgressHUD.h, and then call this method:

[MBProgressHUD showHUDAddedTo:self.view animated:YES];

or if you want to show an activity view inside cell, maybe next to title, you could use something like,

UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[cell.imageView addSubview:activityView];
[activityView startAnimating];

you would then remove the activityView from its superview when you are done.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top