UITableView 删除ROW 程序崩溃
来源:互联网 发布:虫虫大作战刷气球软件 编辑:程序博客网 时间:2024/06/16 14:53
UITableView 删除ROW 调用方法:[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
但是会引起.
'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).'
解决方法.
1.删除DATABASE里的元素,并保证DATABASE的个数与删除后的元素个数相同!
2.[tableView beginUpdates];
3.[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
4.[tableView endUpdates];
如下:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
int row = indexPath.row;
[g_zxgArray removeObjectAtIndex:row];
_needSave = YES;
[self.stockArray removeObjectAtIndex:row];
_recvLines -= 1;
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
// [tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _recvLines;
}
说明 :
It's likely that an NSInternalInconsistencyException
is being raised (check your console).
You need to ensure that when tableView:numberOfRowsInSection:
is called on your UITableViewDelegate
, the count is correct for the section of the cell that was deleted via deleteRowsAtIndexPaths:withRowAnimation:
. i.e. If there were 10 elements in section 0 and you delete one of them viadeleteRowsAtIndexPaths:withRowAnimation:
, tableView:numberOfRowsInSection:
must return 9 for section 0.
还是应该使用ARRARY返回个数, 不应该使用变量. 两个小时... 代码质量.
原文地址:http://blog.csdn.net/allinone2/article/details/7717668
- UITableView 删除ROW 程序崩溃
- UITableView 删除ROW 程序崩溃
- iOS-分组UITableView删除崩溃问题(当删除section中最后一条数据崩溃的情况)
- UITableView删除的时候崩溃NSScanner:nil string argument
- UITableView滑动崩溃
- 滑动删除row
- table 添加删除row
- tableView滑动删除,返回导致程序崩溃问题
- UITableview reloadData偶尔出现崩溃
- 程序崩溃
- 程序崩溃
- How To Handle Row Selection in UITableView
- UITableView刷新指定的row或者section
- UITableView获取cell的row值
- uitableview中刷新单个section和row
- 滑动删除uitableview cell
- UITableView 实现滑动删除
- UITableView 滑动删除数据
- LeetCode之Merge k Sorted Lists
- ps3手柄与ros
- [LeetCode] [动态规划] [编辑距离] Edit Distance
- UML简单概述
- Longest Consecutive Sequence
- UITableView 删除ROW 程序崩溃
- 21分钟 MySQL 入门教程
- JW Player 使用 RTMP 流
- linux设备驱动归纳总结(三):4.ioctl的实现
- linux特殊权限SUID,SGID和SBIT实例演示
- 享元模式
- [Leetcode] Swap Nodes in Pairs (Java)
- 常用的android弹出对话框
- tcp握手