UITableView add cell Animation

后端 未结 4 1214
Happy的楠姐
Happy的楠姐 2020-12-07 18:57

Can any one help me out with UITableView animating issue?

By default we have animation for deleting cell and reordering cells in UITableView

4条回答
  •  无人及你
    2020-12-07 19:41

    You can use the following UITableView method:

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

    Example with self.dataSource being a mutable array and your table only having 1 section:

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

    Note: Subtracted 1 from datasource count since NSIndexPath is zero indexed.

提交回复
热议问题