UITableView - scroll to the top

前端 未结 30 2964
南方客
南方客 2020-11-28 17:22

In my table view I have to scroll to the top. But I cannot guarantee that the first object is going to be section 0, row 0. May be that my table view will start from section

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 17:55

    Note: This answer isn't valid for iOS 11 and later.

    I prefer

    [mainTableView setContentOffset:CGPointZero animated:YES];
    

    If you have a top inset on your table view, you have to subtract it:

    [mainTableView setContentOffset:CGPointMake(0.0f, -mainTableView.contentInset.top) animated:YES];
    

提交回复
热议问题