Activity Indicator not showing up

12,502

Solution 1

If all this code is in one method or in response to one event, then none of the changes to the views are going be visible until you return to the event loop. You set the activityIndicator.hidden to NO and then set it again to YES before the UI has an opportunity to even refresh.

You also apparently stop the animation before you start it.

What you need to do is make the activity indicator visible here and start its animation. Then schedule the work to be done (start an asynchronous network connection, or put some work into a queue, or whatever it is you need to get done) and return from this method so that the UI can refresh, the indicator can be drawn, and the animation can actually start.

Then later at some point after the work is complete, you can hide the indicator and stop the animation. But you can't do all of that on the main thread within one single turn of the event loop. None of your changes will be visible because no drawing at all will happen here while this method is executing (assuming this is on the main thread)

I hope that makes sense?

Solution 2

Now I modified the code to this:

activityIndicator.hidden = NO;

[activityIndicator startAnimating];

[self performSelector:@selector(saveClicked) withObject:nil afterDelay:0.1];    

[self.view bringSubviewToFront:activityIndicator];

and it worked :)

Solution 3

May be, in tableView, instead of self.view , it will be self.navigationController.view ??

Share:
12,502
iOSDev
Author by

iOSDev

Mobile Application Developer by profession

Updated on June 14, 2022

Comments

  • iOSDev
    iOSDev almost 2 years

    I have two issues with activity indicator: 1. Activity Indicator not showing up on UIViewController

    I have activity indicator added in .xib file. On button click it should start animating. and when response from server is received, before going to next page it should stop animating. I am doing it as follows:

    activityIndicator.hidden = NO;
    
    [activityIndicator performSelector:@selector(startAnimating) withObject:nil afterDelay:0.1];
    
    [self.view bringSubviewToFront:activityIndicator];
    
    ....rest of code here....
    
    activityIndicator.hidden = YES;
    
    [activityIndicator stopAnimating];
    
    1. Activity Indicator not showing up on UITableView

    For table view I am doing it same way but on didselectrowatindexpath...

    For tableview I also tried adding activity view to cell accessory, but still not showing up

    In both cases activity Indicator is not showing up.

    Please help

    Thanks

    • Firoze Lafeer
      Firoze Lafeer over 12 years
      Is all this code in one method? What is the context here?