title: UIActivityIndicatorView Never Animates
body: <p>I have a <code>PhotoViewController</code> class with an <code>@property UIActivityIndicatorView* spinner</code>.  <code>FlickrPhotoViewController</code> is a subclass of <code>PhotoViewController</code> that downloads a photo from Flickr and tells the spinner when to start and stop animating.  'updatePhoto' is called every time the view controller is given a Flickr photo:</p>
  
  <pre><code>- (void)updatePhoto { // Download photo and set it
      NSLog("updatePhoto called");
      if (self.spinner) NSLog(@"Spinner exists in updatePhoto");
      dispatch_queue_t downloadQueue = dispatch_queue_create("downloader",
                                                             NULL);
      [self.spinner startAnimating];
  
      dispatch_async(downloadQueue, ^{
          // Download the photo
          dispatch_async(dispatch_get_main_queue(), ^{
              [self.spinner stopAnimating];
              // Set the photo in the UI
              }
          });
      });
  }
  </code></pre>
  
  <p>The above methodology is exactly what I use for displaying a spinning wheel in my table view controllers while the table contents download, and it always works there.  </p>
  
  <p>You will notice at the beginning of <code>updatePhoto</code> I print a message if the <code>UIActivityIndicatorView</code> exists.  I put a similar statement in <code>awakeFromNib</code>, <code>viewDidLoad</code>, and <code>viewWillAppear</code>.  When I run it, this is the exact output I get:</p>
  
  <pre><code>2013-01-31 21:30:55.211 FlickrExplorer[1878:c07] updatePhoto called
  2013-01-31 21:30:55.222 FlickrExplorer[1878:c07] Spinner exists in viewDidLoad
  2013-01-31 21:30:55.223 FlickrExplorer[1878:c07] Spinner exists in viewWillAppear
  </code></pre>
  
  <p>Why does <code>spinner</code> not exist in <code>awakeFromNib</code>?  Docs indicate that "When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established."  Can an IBOutlet be connected without the existence of the object it is connecting to?  In this case, can the <code>spinner</code> IBOutlet be connected to the storyboard without <code>spinner</code> being allocated?</p>
  
  <p>Moving beyond this, I overrode the getter for <code>spinner</code> so that it would instantiate if it does not exist.  As a result, the printing output now looks like this:</p>
  
  <pre><code>2013-01-31 21:48:45.646 FlickrExplorer[2222:c07] Spinner exists in awakeFromNib
  2013-01-31 21:48:45.647 FlickrExplorer[2222:c07] updatePhoto called
  2013-01-31 21:48:45.647 FlickrExplorer[2222:c07] Spinner exists in updatePhoto
  2013-01-31 21:48:45.649 FlickrExplorer[2222:c07] Spinner exists in viewDidLoad
  2013-01-31 21:48:45.650 FlickrExplorer[2222:c07] Spinner exists in viewWillAppear
  </code></pre>
  
  <p>This is what I would have expected to see earlier.  Nevertheless, I still do not get any animation.</p>
  
  <p>Possible problems that I have ruled out:</p>
  
  <ul>
  <li>The <a href="https://stackoverflow.com/questions/10145045/uiactivityindicatorview-not-appearing-ios-5">spinner is the same color as the background</a>, making it invisible. In my project, the background is black and the spinner is white.  </li>
  <li>I am attempting to animate the <code>UIActivityIndicatorView</code> <a href="https://stackoverflow.com/questions/4586665/cant-get-a-spinner-to-appear">while some expensive method is blocking the main thread</a>.  In my project, all my file system I/O and downloading methods are called in a non-main <code>dispatch_async</code> queue.</li>
  <li>The spinner's <a href="https://stackoverflow.com/questions/11884423/ios-uiactivityindicatorview-spinner-not-showing-up">IBOutlet is not hooked up</a>.  In my project, I have double checked this numerous times.  It can be seen from both the storyboard and the PhotoViewController.h file that it is connected.</li>
  </ul>
  
  <p>All three of these possibilities are ruled out by the fact that putting <code>[self.spinner startAnimating];</code> in <code>viewWillAppear</code> makes it successfully animate throughout the download process.</p>
  
  <p>You can download <a href="https://github.com/thoughtadvances/cs193pFlickrExplorer" rel="nofollow noreferrer">this project</a> if you like. Just go to any screen that attempts to display a large photo and you will see that the spinner does not appear.  There are many problems with this project, but this is the one I am focusing on now.</p>
  
  <p>Edit 1:</p>
  
  <ul>
  <li>I added the project's missing dependencies on Git, so the project will
  now compile for you</li>
  </ul>
  
  <p>Edit 2 (2 February 2013):</p>
  
  <ul>
  <li>I am seeing this problem only on the iPhone when the <code>updatePhoto</code> method is called due to another view controller's <code>prepareForSegue</code> setting the photo in the <code>FlickrPhotoViewController</code>.  Is it possible that this contributes to the problem?</li>
  </ul>