title: connectiondidFinishLoading called twice
body: <p>I am new to iphone development. I am able to use the data in <code>connectiondidFinishLoading</code> method.But i see "connection didfinishloading" method called twice.I don't know ,where i am going wrong. Here is my code</p>
  
  <p>Edited code:</p>
  
  <p>again connectionDidFinishLoading called twice</p>
  
  <pre><code> - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
  
         if(textField==CompanyName)
      {
  
          autocompleteTableView.hidden = NO;
  
          NSString *substring = [NSString stringWithString:textField.text];
          substring = [substring stringByReplacingCharactersInRange:range withString:string];
          [self searchAutocompleteEntriesWithSubstring:substring];
          return YES;
          if([CompanyName.text length]==0)
          {
              autocompleteTableView.hidden = YES;
              [popoverController dismissPopoverAnimated:YES];
  
  
          }
      }
      return YES;
  }
  
  - (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring
  {
       data = [[NSMutableData alloc] init];
      self.receivedData = data;
      [data release];
  
      NSURL *jsonUrl =[NSURL URLWithString:[NSString stringWithFormat:@"http://xxxx=%@",substring]];
   NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:jsonUrl];
  
     connection = [[NSURLConnection alloc] initWithRequest:request                                                                 delegate:self ];
      //self.connection = connection;a
     }
  
  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  
  {
  
  
  
      [receivedData setLength:0];
  
  }
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  
  {
  
       [receivedData appendData:data];
  
  
  }
  
  
  
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  
  {
  
  
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
      {
  
          parser = [[NSXMLParser alloc] initWithData:receivedData];
          currentHtmlElement=@"5";
          [parser setDelegate:self];
          [parser setShouldProcessNamespaces:NO];
          [parser setShouldReportNamespacePrefixes:NO];
          [parser setShouldResolveExternalEntities:NO];
          [parser parse];
          [parser release];
  
  
  
          if([arr4 count]!=0)
          {
              self.autocompleteUrls = [[[NSMutableArray alloc] init]autorelease];
  
  
              UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
  
  
              self.autocompleteUrls = [[NSMutableArray alloc] init];
  
              viewForautoCompleteTableView = [[UIView alloc]initWithFrame:CGRectMake (410, 120,270, 250)];
  
  
              autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,270,250) style:UITableViewStyleGrouped];
              autocompleteTableView.delegate = self;
              autocompleteTableView.dataSource = self;
              autocompleteTableView.scrollEnabled = YES;
              autocompleteTableView.backgroundColor = [UIColor lightTextColor];
              autocompleteTableView.rowHeight=28;
  
              autocompleteTableView.backgroundView = nil;
              autocompleteTableView.backgroundColor = [UIColor whiteColor];
  
  
              autocompleteTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
              [autocompleteTableView setSeparatorColor:[UIColor orangeColor]];
              [viewForautoCompleteTableView setFrame:CGRectMake(210,380 ,autocompleteTableView.frame
                                                                .size.width
                                                                ,autocompleteTableView.frame.size.height)];
  
                     [viewForautoCompleteTableView addSubview:autocompleteTableView];
  
              [viewForautoCompleteTableView setBackgroundColor:[UIColor whiteColor]];
              CGRect popoverFrame = viewForautoCompleteTableView.frame;
              popoverContent.view = viewForautoCompleteTableView;
  
              popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
              popoverController.delegate=self;
             [popoverContent release];        
              [popoverController setPopoverContentSize:CGSizeMake(viewForautoCompleteTableView.frame.size.width, viewForautoCompleteTableView.frame.size.height) animated:NO];
  
                         [popoverController presentPopoverFromRect:popoverFrame inView:testscroll permittedArrowDirections:0 animated:YES];
  
  
  
  
              [autocompleteUrls removeAllObjects];
              for(int i=0;i&lt;[arr4 count];i++)
              {
                  NSString *curString = [[arr4 objectAtIndex:i] valueForKey:@"Name"];
                  [autocompleteUrls addObject:curString];
                             }
  
  
  
  
          }
      [autocompleteTableView reloadData];
          [connection cancel];
  
  
      }
  </code></pre>