1

我有一个 UITableView 的展开/折叠系统。当我们打开第一个项目并且我们想要打开另一个项目时会发生此错误。如果当我们打开另一个项目时,第一个项目(打开的)在屏幕上不可见,则会发生错误,但如果第一个项目(打开的)可见,则没有问题。

-(void)expandCollapseItemAtIndex:(NSInteger)row
{
    [self.SousRubriqueTableView beginUpdates];
    if (indexCurrentSousRubrique == row) {
        indexCurrentSousRubrique = -1;
        [self collapseSubItemsAtIndex:row];
    }
    else {
        BOOL shouldCollapse = indexCurrentSousRubrique > -1;

        if (shouldCollapse) [self collapseSubItemsAtIndex:indexCurrentSousRubrique];

        indexCurrentSousRubrique = (shouldCollapse && row > indexCurrentSousRubrique) ? row - [[mesSupportNumerique objectAtIndex:indexCurrentSousRubrique] count] : row;

        [self expandItemAtIndex:indexCurrentSousRubrique];
    }
    [self.SousRubriqueTableView endUpdates];
}

-(void)expandItemAtIndex:(NSInteger)index
{
    NSMutableArray *indexPaths = [NSMutableArray new];
    NSArray *currentSubItems = [mesSupportNumerique objectAtIndex:index];

    NSInteger insertPos = index + 1;
    for (int i = 0; i < [currentSubItems count]; i++) {
        [indexPaths addObject:[NSIndexPath indexPathForRow:insertPos++ inSection:0]];
    }
    [self.SousRubriqueTableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];
    [self.SousRubriqueTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];

    /* CRASH HERE */
    [self.SousRubriqueTableView beginUpdates];
    [self.SousRubriqueTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.SousRubriqueTableView endUpdates];


}

- (void)collapseSubItemsAtIndex:(NSInteger)index
{
    NSMutableArray *indexPaths = [NSMutableArray new];

    for (NSInteger i = index + 1; i <= index + [[mesSupportNumerique objectAtIndex:index] count]; i++) {
        [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
    }

    [self.SousRubriqueTableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];

    [self.SousRubriqueTableView beginUpdates];
    [self.SousRubriqueTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.SousRubriqueTableView endUpdates];

}

reloadRowsAtIndexPaths 更改单元格三角形视图状态(打开/关闭)

4

0 回答 0