开发者

move an UITableViewCell with animation between 2 sections in a UITableView

In one app, there are 2 sections in an UITableView. I hope to move an UITableViewCell with animation from one section to another section in the 开发者_运维知识库UITableView, is it possible?

Welcome any comment

Thanks


UITableView has the answer:

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

So, delete the entry from the first row and add it to the second. There are a number of animations you can select from.

As an example (sorry doing this from memory without a compiler). Assumptions: section0Data holds data for your first section, section1Data holds it for your second.

[self.section0Data removeObjectAtIndex:removeIdx];
[self.section1Data insertObject:entry atIndex:insertIdx];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:removeIdx inSection:0]]
                                              withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:1]]
                                              withRowAnimation:UITableViewRowAnimationFade];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜