从 UITableView 删除部分时应用程序崩溃 [英] crash application while delete section from UITableView

查看:18
本文介绍了从 UITableView 删除部分时应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tableview 我有很多部分,在部分的顶行我有一个删除按钮,我想在点击按钮后删除部分但它崩溃了请帮我我该怎么做??这是代码...

In tableview I have many sections, on the top row of section I have a delete button, I want to do delete section after clicking button but its crashing please help me how can I do this?? here is the code...

//****** adding delete section button
     CellButton *_sectionButton = (CellButton*)[cell viewWithTag:10];
     _sectionButton.hidden = YES;
     _sectionButton.indexPath = indexPath;
     [_sectionButton addTarget:self action:@selector(sectionDeleteButton:)      forControlEvents:UIControlEventTouchUpInside];

-(void)sectionDeleteButton: (id)sender
{
   CellButton *_secbtn = (CellButton*)sender;
   NSInteger sectionNumber = _secbtn.indexPath.section;
   [self.tableView beginUpdates];
   [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionNumber] withRowAnimation:UITableViewRowAnimationAutomatic];
    [self.tableView endUpdates];
    [self.tableView reloadData];

}

错误信息是:

断言失败 -[UITableView _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2013-07-04 04:25:15.921估计[9025:c07] *** 终止应用程序由于未捕获的异常 'NSInternalInconsistencyException',原因:'无效更新:无效的节数.更新后表视图中包含的节数(2)必须等于更新前表视图中包含的节数(2),加上或减去插入或删除的节数(0插入,1已删除)

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1054 2013-07-04 04:25:15.921 estimation[9025:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted)

推荐答案

我猜 numberOfSectionsInTableView: 返回之前的节数.您必须确保您告诉表视图执行的操作也发生在数据源中.也就是说,如果您删除一个部分,那么 numberOfSectionsInTableView 也必须返回一个比以前少 1 的数字.这同样适用于细胞和其他一切.这可能在您收到的错误中有所描述.

I guess the numberOfSectionsInTableView: returns the previous number of sections. You must make sure that what you tell the table view to do also happens in the data source. That is, if you delete a section, then the numberOfSectionsInTableView must also return a number one less than before. The same stands for cells and everything else. This is probably described in the error you get.

这篇关于从 UITableView 删除部分时应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆