title: UISearchBar calls API everytime a letter is typed and not on Searchbutton click
body: <p>Im working on a student project. </p>
  
  <p>At this point our application can call the API and reload the data, but only if I call the XMLParser inside textDidChange. </p>
  
  <p>Meaning: It calls and reloads correctly every time a letter is typed in UISearchBar. I Want the call and reload to only happen when the user clicks on the Search button, but the same code that works in <strong>textDidChange</strong> doesnt work in <strong>searchBarSearchButtonClicked</strong>. </p>
  
  <p>Instead.. The method calls the API only when the searchbutton is pressed <strong>(good)</strong>, recieves the the same information like with <strong>textDidChange</strong>  <strong>(good)</strong> but doesnt reload the UITableView <strong>(bad)</strong>. </p>
  
  <p>I have searched all over SO for the answer to my problem, so I thought I'd post a question instead:) </p>
  
  <p>All of the examples that I've come across only shows how to display the content of an array that matches the users criteria when the user types(contactlist), but doesnt show how to use the searchbutton to reload the uitableView correctly. </p>
  
  <p>Why does the same exact code reload correctly in the delegate method </p>
  
  <p><code>- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText</code> </p>
  
  <p>but not in </p>
  
  <p><code>- (void)searchBarSearchButtonClicked:(UISearchBar *)theSearchBar</code>?</p>
  
  <p>As I said, NSLog prints out the correct data to load the uitableview when the searchButton is clicked, so that is not the problem. </p>
  
  <p>Can anyone point me in the right direction here? :) </p>
  
  <p>My cellForRowAtIndexPath:</p>
  
  <p>`</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      NSString *uniqueIdentifier = @"searchCell";
  
      SearchCell *cell = nil;
  
      cell = (SearchCell *) [self.tableView dequeueReusableCellWithIdentifier:uniqueIdentifier];
  
      if(!cell)
      {
          NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SearchCell" owner:nil options:nil];
  
          for (id currentObject in topLevelObjects) {
              if ([currentObject isKindOfClass:[SearchCell class]]) {
                  cell = (SearchCell *)currentObject;
                  break;
              }
          }
      }
  
      Search *currentSearch = [[searchxmlParser searchhits] objectAtIndex:indexPath.row];
  
      cell.track_label.text = [currentSearch track];
      cell.artist_label.text = [currentSearch artist];
  
      return cell;
  }
  </code></pre>
  
  <p>The requested delegate methods:</p>
  
  <pre><code>- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
  
      NSString *searchurl = [NSString stringWithFormat:@"http://ws.spotify.com/search/1/track?q=%@", [self urlEncodeValue:searchText]];
  
      xmlParser = [[SearchXMLParser alloc] loadXMLByURL:searchurl];
  
      [self.tableView reloadData];
  }
  
  - (void)searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {
  
      NSString *searchurl = [NSString stringWithFormat:@"http://ws.spotify.com/search/1/track?q=%@", [self urlEncodeValue:theSearchBar.text]];
  
      xmlParser = [[SearchXMLParser alloc] loadXMLByURL:searchurl];
  
      [self.tableView reloadData];
  
      [theSearchBar setShowsCancelButton:NO animated:YES];
      [theSearchBar resignFirstResponder];
  }
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      // Return the number of sections.
      return 1;
  }
  
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      // Return the number of rows in the section.
      return [[searchxmlParser searchhits] count];
  }
  </code></pre>
  
  <p>Thank you for your time! :)</p>