title: NSThread to stop process
body: <p>I am using a navigation base application. When I go to next view or back to the previous view, the thread does not stop. Can someone give me a solution for stopping the thread when switching between views? When I switch to next or previous, the application crashes. I use thread like this for downloading the image</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated {
      AppDeleget=  [[UIApplication sharedApplication] delegate];
      ProcessView *Process=[[ProcessView alloc] init];
      [Process SearchProperty:AppDeleget.PropertyURL page:AppDeleget.Page];
      [Process release];
      for(NSDictionary *status in AppDeleget.statuses)
      {       
  
          NSMutableString *pic_string = [[NSMutableString alloc] initWithFormat:@"%@",[status objectForKey:@"picture"]];  
  
          if([pic_string isEqualToString:@""])
          {
  
              [ListPhotos addObject:@"NA"];
  
          }
          else
          {
  
              NSString *str= [[[status objectForKey:@"picture"] valueForKey:@"url"] objectAtIndex:0];
              [ListPhotos addObject:str];  
  
  
          }
      }
      [NSThread detachNewThreadSelector:@selector(LoadImage) toTarget:self withObject:nil];
  
      [AppDeleget.MyProgressView stopAnimating];
      [AppDeleget.Progress removeFromSuperview];
      [super viewWillAppear:animated];
  }
  -(void)LoadImage
  {
      for(int x=0;x&lt;[ListPhotos count];x++)
      {   
          NSData *imageData =[ListPhotos objectAtIndex:x]; 
          id path = imageData;
          NSURL *url = [NSURL URLWithString:path];
          NSLog(@"%@",url);
          NSData *data = [NSData dataWithContentsOfURL:url];
          UIImage *img = [[UIImage alloc] initWithData:data];
          [self performSelectorOnMainThread:@selector(downloadDone:) withObject:img waitUntilDone:NO];
  
      }
  
  }
  -(void)downloadDone:(UIImage*)img {
  
      NSIndexPath *indexPath = [NSIndexPath indexPathForRow:count inSection:0];
  
      if(img == nil)
      {
          TableCell *cell = (TableCell *)[TableView cellForRowAtIndexPath:indexPath]; 
          cell.myImageView.image=[UIImage imageNamed:@"No_image.png"];
          ++count;
          [TableView reloadData]; 
  
      }
      else
      {
          TableCell *cell = (TableCell *)[TableView cellForRowAtIndexPath:indexPath]; 
          cell.myImageView.image=img;
          ++count;
          [TableView reloadData]; 
      }   
  
  }
  </code></pre>