C.Johns
C.Johns

Reputation: 10245

UIActivity Indicator not displaying

Hey guys with some help from a previous question I think I have almost got this working.. code below

-(void)viewDidLoad
{
    [super viewDidLoad];

    //... all your previous charge.

    UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

    activity.hidesWhenStopped = YES;

    activity.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin |
        UIViewAutoresizingFlexibleHeight |
        UIViewAutoresizingFlexibleLeftMargin |
        UIViewAutoresizingFlexibleRightMargin |
        UIViewAutoresizingFlexibleTopMargin |
        UIViewAutoresizingFlexibleWidth;

    [self.tableview addSubview:activity];

    [activity startAnimating];

    [activity performSelector:@selector(stopAnimating) withObject:nil afterDelay:0.5];

}

but nothing appears.. the code is not generating any errors.. so just woundering if I am missing something.

Upvotes: 0

Views: 829

Answers (3)

XJones
XJones

Reputation: 21967

A few things to try:

  • it's not clear if your tableView is appearing and/or populated with data. set a non-white background color for the tableView if there is any doubt as to if the table is there. If you don't see the tableView, fix that first or add the activityIndicatorView as a subview of a different view you know you can see.

  • set a frame for the activityIndicatorView so you know exactly where it's supposed to appear

  • remove the UIViewAutoResizingFlexibleWidth and UIViewAutoResizingFlexibleHeight options from the autoResizingMask of the activityIndicatorView. You don't want the activityIndicatorView to change size based on it's superview.

  • you are using a white activity indicator. make sure it will show up given the colors in your tableview and cells. unless you have a dark colored table, I find the gray activity indicator to be more visible.

  • get rid of your timer to stop the animation, at least until you make sure you can see the activityIndicatorView. this is a wierd UX IMHO. generally you should start/stop the activity indicator based on a process in your app that you want users to be aware of

  • likewise, set hidesWhenStopped = NO until you make sure you can see the activityIndicatorView.

When you can see the activityIndicatorView and everything looks good to your satisfaction you can add the behaviors back that you want.

Upvotes: 1

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39988

It might be that the tableview cell comes above the indicator view.Either you put your activity indicator in tableView.tableHeaderView or in tableView.tableFooterView.

Or
use [self.view addSubview: activity]; to add indicator to the parent view rather than tableView. Hope this will work..

Upvotes: 0

timthetoolman
timthetoolman

Reputation: 4623

You have set it to be hidden when it stops animating and the perform selector stops the animation 0.5 seconds After starting the animation. In addition this is all being done during the view did load method. You cannot guarantee that the view will be visible immediately after the view is loaded. so it could be that the animation starts and stops before the view is even shown!

Try putting the perform selector in the viewDidAppear method and, at least initially, set the delay to a longer time. You can always change the time back once you know it is visible.

Good Luck

Upvotes: 1

Related Questions