如何创建新的部分并使用动画将行移动到它

时间:2014-10-09 11:46:06

标签: 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之后我崩溃了:

  

无法将行移动到新插入的部分

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

1 个答案:

答案 0 :(得分:0)

对于下一代,我的解决方案是使用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];