У меня есть UITableView с расширяемыми строками в разделе 4. Когда одна строка расширяется, другие должны быть свернуты. Я перезагружаю указанные строки и таблицу прокрутки, чтобы иметь расширенный сверху. Вот код:iOS6 UITableView заголовки заголовка раздела
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 4)
{
if (indexPath.row == 0)
{
if (hypoExpanded)
{
hypoExpanded = NO;
[self performSelector:@selector(reloadRowWithScrollForIndexPath:) withObject:indexPath afterDelay:kAnimationDelay];
}
else
{
hypoExpanded = YES;
moodExpanded = NO;
activityExpanded = NO;
NSArray *indexArray = [NSArray arrayWithObjects:indexPath, [NSIndexPath indexPathForRow:1 inSection:4], [NSIndexPath indexPathForRow:2 inSection:4], nil];
[self performSelector:@selector(reloadRowWithScrollForIndexArray:) withObject:indexArray afterDelay:kAnimationDelay];
}
... }
}
- (void)reloadRowWithScrollForIndexArray:(NSArray *)indexArray
{
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:((NSIndexPath *)[indexArray objectAtIndex:0]).row inSection:((NSIndexPath *)[indexArray objectAtIndex:0]).section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (void)reloadRowWithScrollForIndexPath:(NSIndexPath *)indexPath
{
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
switch (section)
{
case 1:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgc-info"]];
break;
case 2:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"in-info"]];
break;
case 3:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bp-info"]];
break;
case 4:
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"per-info"]];
break;
}
return nil;
}
Иногда случайный раздел заголовок (1, 2 или 3) дублируют и накладки ячейки, которая принадлежит к этому разделу. Прокрутка таблицы, чтобы исчезнуть раздел, не помогает. Когда я прокручиваю назад, дублированный заголовок все еще существует. Это происходит только на iOS 6. Вызов performSelectorOnMainThread: тоже не полезно. Кроме того, без вызова scrollToRowAtIndexPath: все работает нормально. Что может вызвать такое поведение?
Вы можете увидеть скриншот здесь:
путы метода titleForHeaderInSection – iPatel
я добавил реализацию viewForHeaderInSection на мой вопрос. Я не использовал метод titleForHeaderInSection. Мне пришлось отредактировать скриншот, чтобы изображения не были видны. – user1277152
так как можно отображать секцию 1,2, ... ?? – iPatel