title: iPhone: How can I have my refresh UIBarButtonItem change to UIActivityIndicator while task is running?
body: <p>I have a refresh button that executes a function to initiate a request and receive a response.  While it's parsing the response I'm changing my last updated text to keep the user informed on what is going on.  I'm hoping though to have the refresh button become the uiactivityindicator while the "procedure" is running.  How can I accomplish this?  Here is a screenshot of my storyboard to help you get and idea of the setup.  Let me know if I can provide anything else. Thanks!</p>
  
  <p><img src="https://i.stack.imgur.com/BfzRk.png" alt="storyboard image"></p>
  
  <p>Image below shows how I created the bottom bar through the simulated metrics drop down list to the right.</p>
  
  <p><img src="https://i.stack.imgur.com/w6793.png" alt="bottom toolbar"></p>
  
  <p>EDIT:</p>
  
  <p>Here is the altered code I used from the marked answer.     </p>
  
  <pre><code>// Create UIActivityIndicator UIBarButtonItem
  UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  [activityView startAnimating];
  UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:activityView];
  
  // Toolbar with LoadingView and LastUpdatedTitle with Flex Spacing
  [self.navigationController.toolbar setItems:(NSArray *)[NSArray arrayWithObjects: loadingView, self.flexSpaceOne, self.lastUpdated, self.flexSpaceTwo, nil]];
  </code></pre>
  
  <p>When I wanted to change it back I simply "reset" my items using the same <code>setItems:arrayWithObjets:</code> method.  Except that time I would change out the loadingview with self.refreshButton.</p>