How to programmatically have UITableView scroll to a specific section

前端 未结 6 1416
离开以前
离开以前 2021-02-13 20:40

In my calendar app, I want my UITableView to scroll to a specific section based on which date is tapped. Current implementation is below:

- (void)calendarDidDate         


        
6条回答
  •  盖世英雄少女心
    2021-02-13 21:23

    When your section has no cells, for example it has just a header or footer, you can use one of the following options:

    let sectionRect = yourTable.rect(forSection: sectionNumber)
    yourTable.setContentOffset(CGPoint(x: sectionRect.origin.x, y: sectionRect.origin.y), animated: true)
    

    or

    let sectionRect = yourTable.rect(forSection: sectionNumber)
    yourTable.scrollRectToVisible(sectionRect, animated: false)
    

提交回复
热议问题