Note that there are some explanatory texts on larger screens.

plurals
  1. POMy tableView only refresh from the UISearchBar only after an additional character is added
    primarykey
    data
    text
    <p>I have a tableView that refreshes with data from an array via the textDidChange function for UISearchBar. The data is correct, but it does not appear in the tableView until after hitting an additional character (so, for instance, if i typed 'Boise' into the search bar, nothing happens, but 'Boise1' will load two cities named 'Boise'..so it's one step behind).</p> <pre><code>- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { //---if there is something to search for--- if ([searchText length] &gt; 0) { NSLog(@"greater than 0!"); isSearchOn = YES; canSelectRow = YES; self.tableView.scrollEnabled = YES; [self performSelector:@selector(someMethod) withObject:nil afterDelay:0]; //[NSThread detachNewThreadSelector:@selector(matchSearchText) // toTarget:self withObject:nil]; //[self matchSearchText]; } else { //---nothing to search--- isSearchOn = NO; canSelectRow = NO; self.tableView.scrollEnabled = NO; } } </code></pre> <p>and in the method that is called:</p> <pre><code> - (void) someMethod { NSLog(@"-------------"); NSLog(@"some Method whut!"); CityLookup *cityLookup = [[CityLookup alloc] findCity:searchBar.text]; // clear array [tableCities removeAllObjects]; if ([cityLookup.citiesList count] &gt; 0) { tableCities = cityLookup.citiesList; int size = [tableCities count]; NSLog(@"there are %d objects in the array", size); } [cityLookup release]; [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:tableCities waitUntilDone:YES]; } </code></pre> <p>and finally the cellForRowAtIndexPath:</p> <pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { int size = [tableCities count]; NSLog(@"there are %d objects in the array NOW", size); static NSString *kCellID = @"cellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } NSString *cellValue = [tableCities objectAtIndex:indexPath.row]; cell.textLabel.text = cellValue; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload