Keep uitableview static when inserting rows at the top

后端 未结 18 2102
名媛妹妹
名媛妹妹 2020-11-29 16:12

I have a tableView that I\'m inserting rows into at the top.

Whilst I\'m doing this I want the current view to stay completely still, so the rows only appear if you

18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 16:24

    Simple solution to disable animations

    func addNewRows(indexPaths: [NSIndexPath]) {
        let addBlock = { () -> Void in
            self.tableView.beginUpdates()
            self.tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .None)
            self.tableView.endUpdates()
        }
    
        tableView.contentOffset.y >= tableView.height() ? UIView.performWithoutAnimation(addBlock) : addBlock()
    }
    

提交回复
热议问题