У меня есть контроллер с двумя массивами, один для обычных результатов; другой для фильтрованных/результатов поиска основан на вводе текста.При поиске, как сделать UITableViewCellAccessoryCheckmark правильной ячейкой?
Только одна ячейка может иметь UITableViewCellAccessoryCheckmark за раз.
Моя проблема может быть описана таким образом;
И.Е.:
- Посмотреть контроллер подается объект Venue; и помечен UITableViewCellAccessoryCheckmark. Это ожидается и правильно.
- Типы пользователей в поисковом запросе используется массив результатов поиска; не однако UITableViewCellAccessoryCheckmark больше не на Venue, который был ранее проверенного на шаге 1.
Я не знаю, почему его не проверяет ячейку.
Визуальные примеры;
Оригинальный формат. Cobo Arena
это заранее выбранное место
-
При вводе; Галочка не в нужном месте
-
Больше типирование: Галочка теперь ушел
-
код ниже
- (void) configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
FCVenue *venue;
if (self.isSearching)
{
venue = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
venue = [self.venues objectAtIndex:indexPath.row];
}
if ([indexPath isEqual:self.selectedIndexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.text = [NSString stringWithFormat:@"%@", venue.name];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", venue.location];
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView cellForRowAtIndexPath:self.selectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
self.selectedIndexPath = indexPath;
[self.tableView reloadRowsAtIndexPaths:@[self.selectedIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
return indexPath;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
FCVenue *venue;
if (self.searching)
{
venue = [self.searchResults objectAtIndex:indexPath.row];
}
else
{
venue = [self.venues objectAtIndex:indexPath.row];
}
self.selectedVenue = venue;
// This method fires a completion block and dismisses the view controller
if (self.completionBlock)
{
self.completionBlock(self, self.selectedVenue);
}
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];
}