Я хочу, чтобы UITableView действовал как аккордеон.При постукивании по строке следует вставить специальный ряд прямо под повернутым рядом, а затем удалить любой другой специальный ряд из предыдущих нажатий.Я пробовал много вещей, но код ниже - моя последняя попытка.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *removeIndex;
for (int i = 0; i < [players count]; i++) {
NSString *player = [players objectAtIndex:i];
if ([player isEqualToString:@"ADJUST_SCORE_ROW"]) {
removeIndex = [NSIndexPath indexPathForRow:i inSection:indexPath.section];
[players replaceObjectAtIndex:i withObject:@"DELETE_ME"];
break;
}
}
[scoreTableView beginUpdates];
NSIndexPath *insertPath;
if (removeIndex && [removeIndex row] < indexPath.row) {
insertPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
} else {
insertPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
}
[players insertObject:@"ADJUST_SCORE_ROW" atIndex:insertPath.row];
[scoreTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:insertPath] withRowAnimation:UITableViewRowAnimationTop];
for (int i = 0; i < [players count]; i++) {
NSString *player = [players objectAtIndex:i];
if ([player isEqualToString:@"DELETE_ME"]) {
[players removeObject:player];
break;
}
}
if (removeIndex) {
[scoreTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:removeIndex] withRowAnimation:UITableViewRowAnimationTop];
}
[scoreTableView endUpdates];
}