ios - 如何使用动画创建新节并将行移动到该节

标签 ios objective-c uitableview

我在tableviewdidSelectRow中有以下代码:

[tableView beginUpdates];
[tableView insertSections:[NSIndexSet indexSetWithIndex:tableView.numberOfSections] withRowAnimation:UITableViewRowAnimationFade];
[tableView moveRowAtIndexPath:indexPath toIndexPath:[NSIndexPath indexPathForRow:0 inSection:tableView.numberOfSections ]];
[tableView endUpdates];

在endUpdates之后,我崩溃了:

无法将行移到新插入的节中

我的错误在哪里?如何使用动画创建新节并将行移动到该节?

最佳答案

对于下一代来说,迟到总比不到好,我的解决方案是使用deleteRow + insertRow而不是moveRow ...,如下代码:

[self.tableView beginUpdates];

[self.tableView insertSections:[NSIndexSet indexSetWithIndex:newSectionNum]
                      withRowAnimation:UITableViewRowAnimationNone];

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:oldIndexPath]
                          withRowAnimation:UITableViewRowAnimationNone];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
                          withRowAnimation:UITableViewRowAnimationNone];

[self.tableView endUpdates];

关于ios - 如何使用动画创建新节并将行移动到该节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26277633/

相关文章:

ios - 如何过滤包含异步下载图像的 UITableviewcells - Swift

ios - NSMutableAttributedString initWithData : causing EXC_BAD_ACCESS on rotation

iphone - 从 UIWebView 检测 window.open()

objective-c - 这个宏有什么问题吗?

ios - 自定义 UITableviewCell 中的多行标签

c# - iOS UI 的 MVVM 交叉图片选择器插件不会在 Bytes 类型 View 模型属性上使用 InMemoryImage 进行更新

objective-c - 在 Objective-C 中创建匿名委托(delegate)对象

iOS - 解包可选值时意外发现 nil

ios - UITableView insertRowsAtIndexPaths 删除单元格分隔符

iphone - Objective-C block 停止 UIGestureRecognizer