Question

I load a RSS feed into a TableView. Before it is loaded, it displays a empty tableview.

Can I let a activity indicator show until it is loaded?

Current code looks like this :

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
    self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
    [self.view addSubview:self.activityIndicator];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
    [view addSubview:self.activityIndicator];
    self.tableView.tableHeaderView = view;
    dispatch_sync(dispatch_get_main_queue(), ^
    {
        [self.tableView reloadData];
        //Remove load feedback
    });
}

This code doesn't show anything I don't know why I expected to have a loading animation at the top but instead a empty space is added at the top of the tableview

Was it helpful?

Solution

The code you've presented puzzles me a bit. I think what you should do is present the activity indicator in the parserDidStartDocument method and remove it in parserDidEndDocument. I suggest creating another UIView property, name it activityIndicatorView, and do something like this:

- (void)parserDidStartDocument:(NSXMLParser *)parser {
    if (!self.activityIndicatorView) {
        self.activityIndicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 60)];
        self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
        self.activityIndicator.center = CGPointMake(self.activityIndicatorView.frame.size.width/2,self.activityIndicatorView.frame.size.height/2);
        [self.activityIndicatorView addSubview:self.activityIndicator];
    }
    self.tableView.tableHeaderView = self.activityIndicatorView;
    [self.activityIndicator startAnimating];
}

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
    [self.tableView reloadData];
    [self.activityIndicator stopAnimating];
    self.tableView.tableHeaderView = nil;
}

I don't know what your project looks like, but I assume you're doing something with the parsed document before reloading the table.

OTHER TIPS

For this just add MBProgressHUD.h and MBProgressHUD.m into your project. Now to show indecator just write:

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

and to hide write:

[MBProgressHUD hideAllHUDsForView:self.view.window animated:YES];

you can get classes from here

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