UITableView add cell Animation

后端 未结 4 1216
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:24

    Swift

    Example array that is the data source for the table view

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

    The following will add a row with animation at the top of the table view.

    // add item 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)
    

    Multiple updates

    If you need to do multiple insertions and/or deletions then surround them with beginUpdates() and endUpdates().

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

    Further reading

    • Documentation

提交回复
热议问题