Have a reloadData for a UITableView animate when changing

前端 未结 17 2888
感动是毒
感动是毒 2020-11-28 17:25

I have a UITableView that has two modes. When we switch between the modes I have a different number of sections and cells per section. Ideally, it would do some cool anima

17条回答
  •  北海茫月
    2020-11-28 17:54

    I can't comment on the top answer, but a swift implementation would be:

    self.tableView.reloadSections([0], with: UITableViewRowAnimation.fade)
    

    you could include as many sections as you want to update in the first argument for reloadSections.

    Other animations available from the docs: https://developer.apple.com/reference/uikit/uitableviewrowanimation

    fade The inserted or deleted row or rows fade into or out of the table view.

    right The inserted row or rows slide in from the right; the deleted row or rows slide out to the right.

    left The inserted row or rows slide in from the left; the deleted row or rows slide out to the left.

    top The inserted row or rows slide in from the top; the deleted row or rows slide out toward the top.

    bottom The inserted row or rows slide in from the bottom; the deleted row or rows slide out toward the bottom.

    case none The inserted or deleted rows use the default animations.

    middle The table view attempts to keep the old and new cells centered in the space they did or will occupy. Available in iPhone 3.2.

    automatic The table view chooses an appropriate animation style for you. (Introduced in iOS 5.0.)

提交回复
热议问题