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];
精彩评论