title: XCode: Stop Animating Activity Indicator after Executing a Method From Another File
body: <p>Ok, this seems like it should be very simple - All I want to do is call my ServerConnect.m (NSObject), NSURL Connection Request Method, from my SignIn.m (ViewController) and stop the UIActivityIndicatorView after the NSURL Request has completed.  Of course, if I do it all on the main thread:</p>
  
  <pre><code>- (IBAction)forgotPassword:(id)sender {    
      [activityIndicator startAnimating];
      connection = [[ServerConnect alloc] init];
      [connection sendUserPassword:email withSecurity:securityID];
      [activityIndicator stopAnimating];
  }
  </code></pre>
  
  <p>Then, everything will then execute concurrently, and the activity indicator will start and stop before the connection method finishes...</p>
  
  <p>Thus, I attempted to place the connection request on a secondary thread:</p>
  
  <pre><code>- (IBAction)forgotPassword:(id)sender {
      [NSThread detachNewThreadSelector: @selector(requestNewPassword:) toTarget:self withObject:userEmail.text];
  }
  
  - (void) requestNewPassword:(NSString *)email
  {
      [self-&gt;thinkingIndicator performSelectorOnMainThread:@selector(startAnimating) withObject:nil waitUntilDone:NO];
  
      //Make NSURL Connection to server on secondary thread
      NSString *securityID = [[NSString alloc] init];
      securityID = @"security";
      connection = [[ServerConnect alloc] init];
      [connection sendUserPassword:email withSecurity:securityID];
  
      [self-&gt;thinkingIndicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
  }
  </code></pre>
  
  <p>But, I don't see the activity indicators here either, which may be due the NSURL Request not functioning properly on the secondary thread (i.e. for some reason, it does not gather an xml string as it does when requested on the main thread).</p>
  
  <p>What is the proper way to architecture my code to make this work?  I am surprised at how much work has been involved in trying to figure out how to get my activity indicator to simply stop after a method from another file has finished executing.  Is there a way to run the code in series (one after another) and not concurrently?  Any help would be appreciated.</p>
  
  <p><strong>Updated to Show: sendUserPassword:(NSString *)withSecurity:(NSString *)</strong></p>
  
  <pre><code>- (void)sendUserPassword:(NSString *)emailString
              withSecurity:(NSString *)passCode;
  {
      NSLog(@"Making request for user's password");
      newUser = NO;
      fbUser = NO;
      forgotPassword = YES;
      NSString *post = [NSString stringWithFormat: @"email=%@&amp;s=%@", emailString, passCode];
      NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
      //Construct the web service URL
      NSURL *url = [NSURL URLWithString:@"http://www.someurl.php"];
      //Create a request object with that URL
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                             cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                         timeoutInterval:90];
      [request setURL:url];
      [request setHTTPMethod:@"POST"];
      [request setHTTPBody:postData];
      //Clear out the existing connection if there is one
      if(connectionInProgress) {
          [connectionInProgress cancel];
      }
      //Instantiate the object to hold all incoming data
      xmlData = [[NSMutableData alloc] init];
  
      //Create and initiate the conection - non-blocking
      connectionInProgress = [[NSURLConnection alloc] initWithRequest: request
                                                             delegate:self
                                                     startImmediately:YES];
  }
  </code></pre>