我试图从我的表视图中删除一行,到目前为止一直没有成功.我一直收到这个错误:
"由于未捕获的异常'NSInternalInconsistencyException'终止应用程序,原因:'无效更新:第0节中的行数无效.更新后的现有节中包含的行数(5)必须等于包含的行数在更新(5)之前的那一部分,加上或减去从该部分插入或删除的行数(0插入,1删除).'"我用来填充表视图的数组在该类中声明,也是我从sqlite db获取我的数组的对象.
我用来尝试删除行的代码如下.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[categoryArray objectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
Run Code Online (Sandbox Code Playgroud)
现在我希望得到回答的问题:
- 如何正确删除行?
- 如果它只是在tableView中留下的那一行,我将面临删除行吗?
- 我可以将方法中使用的tableView更改为我在.h文件中声明的UITableView吗?
非常感谢.
编辑
- 全.m代码
#import "DeleteCategoryTableView.h"
#import "KeyCryptAppAppDelegate.h"
@implementation DeleteCategoryTableView
@synthesize …Run Code Online (Sandbox Code Playgroud)