I have a table view controller with a standard UISearchBar
I want to replace the first row in the table with the text in the search bar as it gets typed. I thought this would work but it doesn't:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
// results is a mutable array with an empty string at index 0
[[self results] replaceObjectAtIndex:0 withObject:searchText];
[[self tableView] reloadData];
}
If I log the results array to the console it is correctly replacing the object, but it is not getting picked up by the table view.
I have the table data source set up as per usual:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self results] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
[[cell textLabel] setText:[[self results] objectAtIndex:[indexPath row]]];
return cell;
}
If I just use insertObjectAtIndex: or insertObject: it does show up the results. Just not when I'm trying to replace first object. Help please! :)