• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用 deleteRowsAtIndexPaths 后未更新 indexPath

用户头像
it1352
帮助1

问题说明

我创建了一个方法,当用户想要删除一个单元格时更新我的 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.

我该怎么做?

正确答案

#1

您所做的基本上是正确的,但是您需要以某种方式重新加载 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
系列文章
更多 icon
同类精品
更多 icon
继续加载