How to scroll to top in IOS7 UITableView?

后端 未结 12 1842
粉色の甜心
粉色の甜心 2020-12-13 00:25

In IOS6 I have the following code to scroll to the top of a UITableView

[tableView setContentOffset:CGPointZero animated:YES];

In IOS7 this

12条回答
  •  没有蜡笔的小新
    2020-12-13 00:38

    Swift 4 UITableViewExtension:

    func scrollToTop(animated: Bool) {
        if numberOfSections > 0 {
            let topIndexPath = IndexPath(row: NSNotFound, section: 0)
            scrollToRow(at: topIndexPath, at: .top, animated: animated)
        }
    }
    

提交回复
热议问题