3

当您点击部分标题时,我有一个带有“折叠”部分的 UITableView。当该部分折叠时,它实际上只是从该部分中删除行。当我尝试将单元格从折叠部分下方的另一个部分重新排序到折叠部分时,应用程序崩溃。我收到此错误:

*** Assertion failure in -[_UITableViewUpdateSupport _setupAnimationForReorderingRow], /SourceCache/UIKit/UIKit-2380.17/UITableViewSupport.m:847

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to create two animations for cell'

奇怪的是,如果我将单元格从折叠部分上方移动到折叠部分,它工作正常。仅当我将其从折叠部分下方移动时,它才会崩溃。

这是我的代码:

-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{    
    if ([proposedDestinationIndexPath section] == 0 && [[JRBTaskStore sharedStore] isTodayCollapsed]) 
        [self hideShowToday];
    else if ([proposedDestinationIndexPath section] == 1 && [[JRBTaskStore sharedStore] isTomorrowCollapsed])
        [self hideShowTomorrow];
    else if ([proposedDestinationIndexPath section] == 2 && [[JRBTaskStore sharedStore] isUpcomingCollapsed])
        [self hideShowUpcoming];
    else if ([proposedDestinationIndexPath section] == 3 && [[JRBTaskStore sharedStore] isSomedayCollapsed])
        [self hideShowSomeday];

    return proposedDestinationIndexPath;
}


-(void)hideShowToday
{
    [self setDayType: TaskDayTypeToday];
    [self hideShowSection: 0 rows: numberOfRowsInToday array: [[JRBTaskStore sharedStore] todayTasks]];
}

-(void)hideShowTomorrow
{
    [self setDayType: TaskDayTypeTomorrow];
    [self hideShowSection: 1 rows: numberOfRowsInTomorrow array: [[JRBTaskStore sharedStore] tomorrowTasks]];
}

-(void)hideShowUpcoming
{
    [self setDayType: TaskDayTypeUpcoming];
    [self hideShowSection: 2 rows: numberOfRowsInUpcoming array: [[JRBTaskStore sharedStore] upcomingTasks]];
}

-(void)hideShowSomeday
{
    [self setDayType: TaskDayTypeSomeday];
    [self hideShowSection: 3 rows: numberOfRowsInSomeday array: [[JRBTaskStore sharedStore] somedayTasks]];
}


-(void)hideShowSection:(int)section rows:(int)numRows array:(NSArray *)array
{    
    if ([array count] > 0 && [[self tableView] numberOfRowsInSection: section] == 0) {
        // Uncollapse the section

        // Create an array of index paths
        NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
        int i = [array count];
        for (int x = 0; x < i; x++) {
            NSIndexPath *ip = [NSIndexPath indexPathForRow: x inSection: section];
            [indexPaths addObject: ip];
        }

        if (dayType == TaskDayTypeToday) {
            numberOfRowsInToday = [array count];
            [[JRBTaskStore sharedStore] setIsTodayCollapsed: NO];
        }
        if (dayType == TaskDayTypeTomorrow) {
            numberOfRowsInTomorrow = [array count];
            [[JRBTaskStore sharedStore] setIsTomorrowCollapsed: NO];
        }
        if (dayType == TaskDayTypeUpcoming) {
            numberOfRowsInUpcoming = [array count];
            [[JRBTaskStore sharedStore] setIsUpcomingCollapsed: NO];
        }
        if (dayType == TaskDayTypeSomeday) {
            numberOfRowsInSomeday = [array count];
            [[JRBTaskStore sharedStore] setIsSomedayCollapsed: NO];
        }

        // Getting the error here
        [[self tableView] insertRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationAutomatic];

    }
    else if ([array count] > 0 && [[self tableView] numberOfRowsInSection: section] > 0) {
        // Collapse the section

        // Find the index paths of the rows and delete them
        NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
        int i = [[self tableView] numberOfRowsInSection: section];
        for (int x = 0; x < i; x++) {
            NSIndexPath *ip = [NSIndexPath indexPathForRow: x inSection: section];
            [indexPaths addObject: ip];
        }

        if (dayType == TaskDayTypeToday) {
            numberOfRowsInToday = 0;
            [[JRBTaskStore sharedStore] setIsTodayCollapsed: YES];
        }
        if (dayType == TaskDayTypeTomorrow) {
            numberOfRowsInTomorrow = 0;
            [[JRBTaskStore sharedStore] setIsTomorrowCollapsed: YES];
        }
        if (dayType == TaskDayTypeUpcoming) {
            numberOfRowsInUpcoming = 0;
            [[JRBTaskStore sharedStore] setIsUpcomingCollapsed: YES];
        }
        if (dayType == TaskDayTypeSomeday) {
            numberOfRowsInSomeday = 0;
            [[JRBTaskStore sharedStore] setIsSomedayCollapsed: YES];
        }

        [[self tableView] deleteRowsAtIndexPaths: indexPaths withRowAnimation: UITableViewRowAnimationTop];

    }
    else if ([array count] == 0) {
        // There's nothing in the section
    } 
}
4

0 回答 0