iOS:' NSInternalInconsistencyException',原因:'尝试删除第4部分中的第1行,但更新前只有3个部分'

时间:2015-01-13 12:44:31

标签: ios objective-c uitableview nsindexpath

我创建了一个下拉表格视图单元格,但是当插入和删除行进入部分应用程序崩溃时出现以下错误,

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 1 from section 4, but there are only 3 sections before the update'

我正在按钮点击时用两个不同的数组重新加载tableview的数据。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tagforTable==1)
        return [updateDataArray count];
    else
        return [offersDataArray count];
}
- (void)didSelectCellRowFirstDo:(BOOL)firstDoInsert nextDo:(BOOL)nextDoInsert
{
    [self.notificationTable beginUpdates];

    int section;
    self.isOpen = firstDoInsert;

    Cell1 *cell = (Cell1 *)[self.notificationTable cellForRowAtIndexPath:self.selectIndex];
    [cell changeArrowWithUp:firstDoInsert];


    section = self.selectIndex.section;

    dbObj=[[DatabaseHelper alloc]init];
    if (tagforTable==1)
    {
        [dbObj updateTagUpdate:section];
    }
    else if(tagforTable==2)
    {
        [dbObj updateTagOffers:section];
    }
    [upCount removeAllObjects];
    [ofCount removeAllObjects];
    upCount=[dbObj SelectTagForUpdate];
    ofCount=[dbObj SelectTagForOffers];
    notificationBtn.badgeValue = [NSString stringWithFormat:@"%d",[upCount count]+[ofCount count]];
    notificationBtn.badgeBGColor = [UIColor redColor];


    NSMutableArray* rowToInsert = [[NSMutableArray alloc] init];

    NSIndexPath* indexPathToInsert = [NSIndexPath indexPathForRow:1 inSection:section];
    [rowToInsert addObject:indexPathToInsert];

    if (firstDoInsert)
    {   [self.notificationTable insertRowsAtIndexPaths:rowToInsert withRowAnimation:UITableViewRowAnimationTop];
    }
    else
    {
        [self.notificationTable deleteRowsAtIndexPaths:rowToInsert withRowAnimation:UITableViewRowAnimationTop];
    }

    [rowToInsert release];

    if (nextDoInsert) {
        self.isOpen = YES;
        self.selectIndex = [self.notificationTable indexPathForSelectedRow];
        [self didSelectCellRowFirstDo:YES nextDo:NO];
    }
    if (self.isOpen) [self.notificationTable scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];
    [self.notificationTable endUpdates];

}
我出错的地方?帮助!

0 个答案:

没有答案