Have a reloadData for a UITableView animate when changing

前端 未结 17 2890
感动是毒
感动是毒 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 18:08

    UITableView has a field called 'indexPathsForVisibleRows' that you can use to animate the visible rows using the 'reloadItemsAtIndexPaths' method.

        guard let indexPaths = tableView.indexPathsForVisibleRows
        else { return }
        
        self.tableView.layoutIfNeeded()
        self.tableView.reloadItemsAtIndexPaths(indexPaths, animationStyle: .automatic)
    

提交回复
热议问题