У меня есть контроллер табличного представления со стандартным UISearchBar
Я хочу заменить первую строку в таблице текстом в строке поиска по мере ввода.Я думал, что это сработает, но это не так:
- (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];
}
Если я записываю массив результатов в консоль, он корректно заменяет объект, но не попадает в представление таблицы.
У меня есть источник данных таблицы, настроенный как обычно:
- (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;
}
Если я просто использую insertObjectAtIndex: или insertObject: он показывает результаты.Только не тогда, когда я пытаюсь заменить первый объект.Помогите, пожалуйста!:)