ios – 无效更新:部分中的行数无效

ios – 无效更新:部分中的行数无效,第1张

概述我正在使用Microsoft Azure服务开发项目.在删除行时,我收到此错误: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows 我正在使用Microsoft Azure服务开发项目.在删除行时,我收到此错误:

Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'InvalID update: invalID number of rows in section 0.  The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2),plus or minus the number of rows inserted or deleted from that section (0 inserted,1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,0 moved out).

表加载和删除行的代码如下:

- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw {        return 3;}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section {    //medicine List    if (section == 0) {        NSArray *sectionInfo = [self.fetchedResultsController1 fetchedobjects];        return [sectionInfo count];    }    //allergy List    else if (section == 1) {        NSArray *sectionInfo = [self.fetchedResultsController2 fetchedobjects];        return [sectionInfo count];    }    //notes List    else if (section == 2){        NSArray *sectionInfo = [self.fetchedResultsController3 fetchedobjects];        return [sectionInfo count];    }    else        return 0; }- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    static Nsstring *cellIDentifIEr = @"mcell";    MedicationtableVIEwCell *cell = (MedicationtableVIEwCell *)    [tableVIEw dequeueReusableCellWithIDentifIEr:cellIDentifIEr forIndexPath:indexPath];    //  Add utility buttons     NSMutableArray *rightUtilitybuttons = [NSMutableArray new];    [rightUtilitybuttons sw_addUtilitybuttonWithcolor: [UIcolor colorWithRed:1.0f green:0.231f blue:0.188 Alpha:1.0f] Title:@"Delete"];    switch (indexPath.section) {        case 0: {            NSManagedobject *item = [self.fetchedResultsController1 objectAtIndexPath:indexPath];            cell.textLabel.text = [item valueForKey:@"name"];            break;        }        case 1: {            NSManagedobject *item = [self.fetchedResultsController2 objectAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];            cell.textLabel.text = [item valueForKey:@"name"];            break;        }        case 2: {            NSManagedobject *item = [self.fetchedResultsController3 objectAtIndexPath: [NSIndexPath indexPathForRow:indexPath.row inSection:0]];            cell.textLabel.text = [item valueForKey:@"Title"];            break;        }        default:            break;    }    cell.rightUtilitybuttons = rightUtilitybuttons;    cell.delegate = self;    return cell;}- (voID)swipeabletableVIEwCell:(SWtableVIEwCell *)cell dIDTriggerRightUtilitybuttonWithIndex:(NSInteger)index { // Delete button is pressed NSIndexPath *cellindexPath = [self.medicationstableVIEw indexPathForCell:cell]; //fetchingg data from local store first NSManagedobject *item = [self.fetchedResultsController1 objectAtIndexPath:[NSIndexPath indexPathForRow:cellindexPath.row inSection:0]];   NSMutableArray *keys = [[NSMutableArray alloc] initWithObjects:@"ID",@"name",@"userID",nil];   NSMutableArray *values = [[NSMutableArray alloc] initWithObjects: [item valueForKey:@"ID"],[item valueForKey:@"name"],[item valueForKey:@"userID"],nil];    //creating dictionary of data    NSDictionary *dict = [[NSDictionary alloc] initWithObjects:values forKeys:keys];    //calling delete fucntion    [self.authService deleteItem:self.synctable withDict:dict completion:^{    //removing row from table vIEw    [self.medicationstableVIEw reloadData];    [self.medicationstableVIEw deleteRowsAtIndexPaths:@[cellindexPath] withRowAnimation:UItableVIEwRowAnimationRight];      }];      break;}

请告诉我哪里出错了.在先谢谢!!!!

解决方法 In – (voID)swipeabletableVIEwCell:dIDTriggerRightUtilitybuttonWithIndex:

你需要删除

[self.medicationstableVIEw reloadData];

要么

[self.medicationstableVIEw deleteRowsAtIndexPaths:@[cellindexPath] withRowAnimation:UItableVIEwRowAnimationRight];

因为在第一行调用reloadData时,它会使用新数据源重新加载tablevIEw,并再次调用deleteRowsAtIndexPaths尝试删除之前通过调用reloadData删除的行.

总结

以上是内存溢出为你收集整理的ios – 无效更新:部分中的行数无效全部内容,希望文章能够帮你解决ios – 无效更新:部分中的行数无效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1069189.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存