为什么我写删除UITableView行的代理时心理出了问题题

2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年4月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第三2015年3月 移动开发大版内专家分月排行榜第三2014年10月 移动开发大版内专家分月排行榜第三
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第一2015年4月 移动开发大版内专家分月排行榜第一2014年9月 移动开发大版内专家分月排行榜第一
2015年3月 移动开发大版内专家分月排行榜第二2014年8月 移动开发大版内专家分月排行榜第二
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。Pages: 1/2
主题 : 删除cell一直崩溃。。。
级别: 侠客
UID: 482259
可可豆: 261 CB
威望: 256 点
在线时间: 190(时)
发自: Web Page
删除cell一直崩溃。。。&&&
收藏功能用归档实现的,现在需要做一个删除某一行cell的功能,代码如下:- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{&&&&if (editingStyle == UITableViewCellEditingStyleDelete)&&&&{&&&&&&&&//删除数据源&&&&&&&&[[self unArchiverCollectArray] removeObjectAtIndex:indexPath.row]; //[self unArchiverCollectArray]反归档出来的包含收藏数据的数组&&&&&&&&&&&&&&&&//从界面上删除&&&&&&&&[_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];&&&&&&&&&&&&&&&&//NSMutableData *data = [NSMutableData data];&&&&&&&&//NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];&&&&&&&&//[archiver encodeObject:[self unArchiverCollectArray] forKey:@&collectData&];&&&&&&&&//[archiver finishEncoding];&&&&&&&&//NSString *newCollectPath = [[self documentsPath] stringByAppendingPathComponent:@&collectData.txt&];&&&&&&&&//[data writeToFile:newCollectPath atomically:YES];&&&&&&&&&&&&&&&&//[self.tableView beginUpdates];&&&&&&&&&&&&&&&&//[self.tableView endUpdates];&&&&&&&&&&&&&&&&//[self.tableView reloadData];&&&&}}我尝试过多种方法,添加保护、刷新表视图、重新归档删除后的数组,但都行不通,崩溃原因如下:*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-/UITableView.m:1623 21:35:58.823 YaoDaoBingChu[] *** 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 (7) must be equal to the number of rows contained in that section before the update (7), 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).'各位大侠,这个问题该如何解决?
级别: 圣骑士
可可豆: 1472 CB
威望: 1474 点
在线时间: 1119(时)
发自: Web Page
我一直的做法一般就两步:1. 删除数组中的那条数据2. 刷新tableview从界面上删除,这行我没用过
级别: 侠客
UID: 482259
可可豆: 261 CB
威望: 256 点
在线时间: 190(时)
发自: iPhone
大神们,求质地!!
级别: 侠客
UID: 485830
可可豆: 186 CB
威望: 171 点
在线时间: 39(时)
发自: Web Page
&& //删除数据源&&&&&&&&[[self unArchiverCollectArray] removeObjectAtIndex:indexPath.row]; //[self unArchiverCollectArray]反归档出来的包含收藏数据的数组&&&&&&&&&&&&&&&&//从界面上删除&&&&&&&&[_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];这两行检查一下,是不是一一对应的删了。写法没用错误,这是常用的方法。
级别: 新手上路
可可豆: 54 CB
威望: 44 点
在线时间: 578(时)
发自: Web Page
numofrows 返回的数量写死了或者不对导致的
级别: 新手上路
UID: 487914
可可豆: 4 CB
威望: 2 点
在线时间: 3(时)
发自: Web Page
回 4楼() 的帖子
楼上正解!!!!!!!
级别: 侠客
UID: 501467
可可豆: 598 CB
威望: 390 点
在线时间: 298(时)
发自: Web Page
看到这个方法1. 删除数组中的那条数据2. 刷新tableview学了不少的东西
级别: 新手上路
可可豆: 82 CB
威望: 72 点
在线时间: 476(时)
发自: Web Page
&& //删除数据源&&&&&&&&[[self unArchiverCollectArray] removeObjectAtIndex:indexPath.row]; //[self unArchiverCollectArray]反归档出来的包含收藏数据的数组&&&&&&&&&&&&&&&&//在这个位置numberOfRowsInSection的返回值也要减1&&&&&&&&//从界面上删除&&&&&&&&[_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
级别: 新手上路
UID: 285906
可可豆: 180 CB
威望: 112 点
在线时间: 98(时)
发自: Web Page
你的代码没问题1、如同其他楼上说的,你的numberOfRowsInSection是写死的2、你是用多section来做的,而不是多cell,那么要删除的是section而不是cell应该调用deleteSection的接口
级别: 新手上路
可可豆: 12 CB
威望: 12 点
在线时间: 7(时)
发自: Web Page
lz的这个问题解决了么?我也遇到了相同的问题?
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
returnUITableViewCellEditingStyleD
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
if (editingStyle == UITableViewCellEditingStyleDelete)
[self.items removeObjectAtIndex:indexPath.row];
[tableView reloadData];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
NSLog(@"Row %@ tapped.", self.items[indexPath.row]);
在ios6环境下,上段代码运行正常。但是在ios7环境下,我做了如下操作:当tableview中的一行被删除并更新tablview后,被删除行的下一行的点击事件将被忽略,导致点击该行无反应(双击才有反应)。很奇怪是不是,下面将解释原因。
当tableview中的某行被选中删除后,tableview将处于编辑(editing)状态,所以你需要将tableview中的状态更换成选择(selection)模式,更改代码如下:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
if (editingStyle == UITableViewCellEditingStyleDelete)
[self.items removeObjectAtIndex:indexPath.row];
// Turn off editing state here
tableView.editing = NO;
[tableView reloadData];
阅读(...) 评论()

我要回帖

更多关于 滁州张祥安出了问题 的文章

 

随机推荐