title: iPhone Busy View
body: <p>I am trying to get a busy view displayed during a search process however it never seems to display.</p>
  
  <p><strong>What I am trying to achieve</strong></p>
  
  <ol>
  <li>User clicks on search button once they have entered the text in a UISearchBar.</li>
  <li>The text entered is delegated to searchBarSearchButtonClicked.</li>
  <li>Show a "Busy view" which is a UIView containing a UIActivityIndicatorView to indicate the search is underway.</li>
  <li>Perform a search which communicates with a website.</li>
  <li>On search completion remove the "Busy View".</li>
  </ol>
  
  <p><strong>Whats wrong</strong></p>
  
  <p>The search process is working fine, using the debugger I can see it moving through the searchBarSearchButtonClicked function fine however the "Busy View" never appears. The search takes 2-3 seconds so in theory I should see my "Busy View" appear for those 2-3 seconds.</p>
  
  <hr>
  
  <p><strong>Code Attempt 1 -</strong> Add and remove the "Busy View" from the superview**</p>
  
  <pre><code>- (void)searchBarSearchButtonClicked:(UISearchBar *)activeSearchBar {
  
   [activeSearchBar setShowsCancelButton:NO animated:YES];
   [activeSearchBar resignFirstResponder];
   [busyView activateSpinner]; //start the spinner spinning
   [self.view addSubview:busyView]; //show the BusyView
  
   Search *search = [[Search alloc]init];
   results = [search doSearch:activeSearchBar.text];
  
   [busyView deactivateSpinner]; //Stop the spinner spinning
   [busyView removeFromSuperview]; //remove the BusyView
   [search release]; search = nil;
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Results Of Attempt 1 -</strong> It does not appear, however if I comment out the removeFromSuperview call the Busy View remains on screen.</p>
  
  <hr>
  
  <p><strong>Code Attempt 2 -</strong> using animations</p>
  
  <pre><code>- (void)searchBarSearchButtonClicked:(UISearchBar *)activeSearchBar {
  
  
  
  [activeSearchBar setShowsCancelButton:NO animated:YES]; 
   [activeSearchBar resignFirstResponder];
  
   [UIView beginAnimations:nil context:nil];
   [UIView setAnimationDuration:0];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(animationDidStop)];
  
   [busyView activateSpinner]; //start spinning the spinner
   [self.view addSubview:busyView]; //show the busy view
  
   [UIView commitAnimations];
  
   Search *search = [[Search alloc]init];
   results = [search doSearch:activeSearchBar.text];
  
  
   [UIView beginAnimations:nil context:nil];
   [UIView setAnimationDuration:0];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(animationDidStop)];
  
   [busyView deactivateSpinner]; //sets stops the spinner spinning
   [busyView removeFromSuperview]; //remove the view
  
   [UIView commitAnimations];
   [search release]; search = nil;
  }
  </code></pre>
  
  <p><strong>Results of attempt 2 -</strong> Did not see the "Busy View" appear</p>