UITableView添加单元格animation

任何一个可以帮助我与UITableViewanimation问题?

默认情况下,我们有用于删除单元格和重新sortingUITableView单元格的animation。

我们可以有animation添加单元格,如果是的话,怎么做。

我已经检查了Three20 ,并没有得到如何twitter已经做了MyProfile> ReTweets下的表扩展animation。

要使用UITableView的现有animation,不用Three20 frameowrk,来尝试它。

你可以使用下面的UITableView方法:

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

self.dataSource是一个可变数组,而您的表只有一个部分的示例:

 [self.dataSource addObject:@"New Item"]; NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:[self.dataSource count]-1 inSection:0]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 

注意:从数据源计数中减去1,因为NSIndexPath是零索引。

迅速

示例数组是表视图的数据源

 var myArray = ["Cow", "Camel", "Sheep", "Goat"] 

以下将在表视图的顶部添加一个animation行。

 // add message to current array myArray.insert("Horse", atIndex: 0) // insert row in table let indexPath = NSIndexPath(forRow: 0, inSection: 0) tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade) 

多个更新

如果您需要执行多次插入和/或删除,请使用beginUpdates()endUpdates()它们包围。

 tableView.beginUpdates() tableView.insertRowsAtIndexPaths([addIndexPath1, addIndexPath2, ...], withRowAnimation: .Fade) tableView.deleteRowsAtIndexPaths([deleteIndexPath1, deleteIndexPath2, ...], withRowAnimation: .Fade) tableView.endUpdates() 

进一步阅读

  • 文档

使用reloadRowsAtIndexPaths:indexPath

  tableView.beginUpdates() [tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationAutomatic]; tableView.endUpdates() 

我希望这能帮到您..