使用 deleteRowsAtIndexPaths 后未更新 indexPath
问题说明
我创建了一个方法,当用户想要删除一个单元格时更新我的 UITableView.
I created a method which updates my UITableView when the user wants to delete a cell.
-(void)removeMoreFriendsRow:(NSNotification *)notification {
NSDictionary *d = [notification userInfo];
NSIndexPath *index = [d objectForKey:@"indexPath"];
[self.p_currentFriends removeObjectAtIndex:index.row];
[self.o_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationRight];
}
p_currentFriends 是一个 NSMutableArray,它包含 UITableView 打印的所有对象.
p_currentFriends is a NSMutableArray which contains all the objects printed by the UITableView.
这个方法用一次就可以,但是用多了就不行了.
This method works fine when I use it once, but it fails when I use it more than once.
每次调用 deleteRowsAtIndexPaths 时,indexPath 似乎都保持不变.
It appears that the indexPath stay the same at each call of deleteRowsAtIndexPaths.
例如
- 在第一次调用时,用户点击第二个单元格,indexPath = [0,1] 并删除正确的单元格,
- 在第二次调用时,用户点击第三个单元格并且 indexPath = [0,3] 而不是 [0,2]
我发现让它起作用的唯一方法是使用 reloadData,但我想在删除单元格时制作动画.
The only way I found to make it works is to use reloadData but I want to have a animation on the cell deletion.
我该怎么做?
正确答案
您所做的基本上是正确的,但是您需要以某种方式重新加载 tableView
.如果您不想重新加载整个 tableView
,请使用它,它还会为您提供 animation
-
What you're doing is basically correct, but you'll need to reload the tableView
somehow. If you don't want to reload the whole tableView
, use this, which gives you an animation
as well -
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:sectionNum];
[self.o_table reloadSections:indexSet
withRowAnimation:UITableViewRowAnimationFade];
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfhgee
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20