Ваш вызов reloadRowsAtIndexPaths : заставит представление таблицы перезагрузить заданные ячейки и, следовательно, у таблицы больше не будет выделенной строки в этой позиции.Метод cellforRowAtIndexPath представляет собой запрос источника данных на предоставление строки для заданного пути индекса.Если вам необходимо определить, была ли выбрана ячейка до запроса, вы можете сохранить indexPath выбранной строки в элементе.Затем проверьте член в вашем cellForIndexPathMethod.
В следующем примере кода предполагается, что вы используете ARC для управления памятью.
- (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];
}
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d_%d", indexPath.section, indexPath.row];
// Configure the cell...
if(selectedIndexPath != nil) {
NSLog(@"Selected section:%d row:%d", selectedIndexPath.section, selectedIndexPath.row);
//TODO:Provide a custom cell for the selected one.
//Set the selectedIndexPath to nil now that it has been handled
selectedIndexPath = nil;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Store the selected indexPath
selectedIndexPath = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}