how to retrieve all visible table section header views

后端 未结 10 587
渐次进展
渐次进展 2020-12-31 04:44

is there a way to get all the section header views that are visible?

something similar to UITableView\'s visibleCells instance method..

10条回答
  •  爱一瞬间的悲伤
    2020-12-31 05:11

    Swift 4+ Clean and simple, without duplicities:

    extension UITableView {
    
        var visibleHeaderViews: [UITableViewHeaderFooterView] {
            guard let visibleSectionsIndexPaths = indexPathsForVisibleRows?.compactMap({ $0.section }) else { return [] }
    
            return Set(visibleSectionsIndexPaths).compactMap { headerView(forSection: $0) }
        }
    
    }
    

提交回复
热议问题