错误'重新排序时尝试为单元格创建两个动画'

时间:2013-04-28 02:43:42

标签: ios objective-c animation uitableview

我有一个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
    } 
}

0 个答案:

没有答案