uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of ro

本文探讨了在iOS开发过程中遇到的删除数据时报错的问题,并提供了有效的解决方法。通过先删除数据库中的数据,再刷新UITableView,避免了因数据更新导致的系统错误。同时解释了错误产生的原因及解决方案,帮助开发者避免类似问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、问题

删除一行时,报错。。。。

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 (0) must be equal to the number of rows contained in that section before the update (3), 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).'



2、解决办法

背景:

- (void)loadData {

   

        NSMutableArray* mutArray= //[DAO getdata]; 从数据库或是数据源取数据

        Array* array = [mutArray mutableCopy];  //因为要动态添加的数据,所以用了NSMutableArray,  array和mutArray 装得数据其实是一样的

        [self.tableView reloadData];



办法: 先删数据库  再删table view。。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

                 

                

        //[DAO delete]  先数据库删除,实现略

        [mutArray removeObjectAtIndex:indexPath.row];

         array = [mutArray mutableCopy];

        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];


3、原因



deleteRowsAtIndexPaths后Section里面的rows数量,和系统调用numberOfRowsInSection时rows数量不一致


可以Bug 去看 。。。。



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    // Return the number of rows in the section.

     NSLog(@"numberOfRowsInSection==%lu",(unsigned long)[array count]);

     return [array count];

}




引用:Uncaught ReferenceError: jQuery is not defined。这个报错意味着在代码中使用了jQuery,但是没有正确地引入jQuery库。解决这个问题的方法是将jQuery库的引入代码放在其他所有JavaScript代码的前面。具体来说,错误的代码放置了: ``` <script src="其他js文件"></script> <script> // 使用了jQuery的代码 </script> ``` 而正确的代码应该是将jQuery库的引入代码放在其他JavaScript代码之前: ``` <script src="jQuery库"></script> <script src="其他js文件"></script> <script> // 使用了jQuery的代码 </script> ``` 引用:问题:BootCDN中axios失效,无法通过里面的script标签引入axios。 解决方法:本地自行添加axios.js文件,然后在需要的地方引用。通过以下代码引入axios.js文件: ``` <script src="./axios.js"></script> ``` 问题:请告诉我,uncaught exception: ReferenceError: use is not defined。 这个错误提示表明在代码中使用了一个未定义的变量use。要解决这个问题,您需要确保在使用变量use之前,它已经被正确地定义和赋值。您可以通过在代码中添加如下的语句来定义和赋值变量use: ``` var use = "some value"; ``` 确保将变量use定义在使用它的代码之前。这样,您就可以避免出现uncaught exception: ReferenceError: use is not defined的错误。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [easyui解决:Uncaught ReferenceError: jQuery is not defined](https://download.youkuaiyun.com/download/weixin_38750761/14044307)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Uncaught ReferenceError: axois is not defined](https://blog.youkuaiyun.com/qq_41425646/article/details/129861414)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值