eonist / CellHider

πŸ™ˆ Hide cells in UITableView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

codebeat badge Tests

CellHider πŸ™ˆ

Hide cells in UITableView

Installation:

  • SPM: .package(url: "https://github.com/passbook/CellHider.git", .branch("master"))

Note:

extension TableView {
   /**
    * On cell-tap
    */
   func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      CellHider.hide(table: self, indexPaths: [indexPath], isHidden: true) // hides cells you click
   }
   /**
    * Returns the height of each cell
    * - Note: we have to set height to zero when hiding cells
    */
   func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
      let cell = self.subviews.compactMap { $0 as? UITableViewCell }.first { self.indexPath(for: $0) == indexPath } // this is the only way to get access to cell during creation
      return cell?.isHidden ?? false ? CGFloat.leastNonzeroMagnitude : 60 // or use UITable.automatic...
   }
}

Fun fact:

  • An alternative name idea for this repo was: "peek-a-boo"

About

πŸ™ˆ Hide cells in UITableView

License:MIT License


Languages

Language:Swift 100.0%