How to get a UITableView's visible sections?

前端 未结 12 1790
轻奢々
轻奢々 2020-12-14 19:24

UITableView provides the methods indexPathsForVisibleRows and visibleCells, but how can I get the visible sections?

12条回答
  •  情歌与酒
    2020-12-14 20:10

    Have you tried this in Swift 4?

    let sections = tableView.indexPathsForVisibleRows?.map { $0.section } ?? []
    for section in sections { 
        print(String(format: "%d", section)) 
    }
    

提交回复
热议问题