UITableView - scroll to the top

前端 未结 30 2730
南方客
南方客 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:49

    UITableView is a subclass of UIScrollView, so you can also use:

    [mainTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
    

    Or

    [mainTableView setContentOffset:CGPointZero animated:YES];
    

    And in Swift:

    mainTableView.setContentOffset(CGPointZero, animated:true)
    

    And in Swift 3 & above:

    mainTableView.setContentOffset(.zero, animated: true)
    

提交回复
热议问题