Determine if a tableview cell is visible

前端 未结 8 1276
野性不改
野性不改 2020-12-02 13:13

Is there any way to know if a tableview cell is currently visible? I have a tableview whose first cell(0) is a uisearchbar. If a search is not active, then hide cell 0 via a

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 13:29

    I use this in Swift 3.0

    extension UITableView {
    
        /// Check if cell at the specific section and row is visible
        /// - Parameters:
        /// - section: an Int reprenseting a UITableView section
        /// - row: and Int representing a UITableView row
        /// - Returns: True if cell at section and row is visible, False otherwise
        func isCellVisible(section:Int, row: Int) -> Bool {
            guard let indexes = self.indexPathsForVisibleRows else {
                return false
            }
            return indexes.contains {$0.section == section && $0.row == row }
        }  }
    

提交回复
热议问题