У меня есть контроллер табличного представления со стандартным UISearchBarUISearchBarDelegate и UITableView не работают вместе?
Я хочу заменить первую строку в таблице текстом в строке поиска, когда он набирается. я думал, что это будет работать, но это не делает:
- (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: он показывает итоги. Просто не тогда, когда я пытаюсь заменить первый объект. Помогите пожалуйста! :)
Попробуйте убить эту строку: 'if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier]; } '. Причина, по которой я говорю, это то, что вы распределяете каждую ячейку. – Gobot
Вот сообщение, которое я спрятал прочь: http://stackoverflow.com/questions/2286669/iphone-how-to-purge-a-cached-uitableviewcell – Gobot