Latest 2.1.1
Homepage https://github.com/AaronBratcher/TableViewHelper
License MIT
Platforms ios 9.0
Authors

Swift Struct to dynamically hide and show UITableView Rows by name. This is written in Swift 3.

Includes sample app.

Installation

  • Cocoapods
  • Include TableViewHelper.swift in your project

Basics

Instantiate a copy of the class with a reference to the tableView:

helper = TableViewHelper(tableView:tableView)

Add all cells that can show to the helper giving each cell a name (multiple cells can have the same name):

helper.addCell(section: 0, cell: tableView.dequeueReusableCellWithIdentifier("S0R0")! as UITableViewCell, name: "S0R0")
helper.addCell(section: 0, cell: tableView.dequeueReusableCellWithIdentifier("S0R1")! as UITableViewCell, name: "S0R1")

helper.addCell(section: 1, cell: tableView.dequeueReusableCellWithIdentifier("S1R0")! as UITableViewCell, name: "S1R0")

Reference the helper class for relevant UITableView calls:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return helper.numberOfSections()
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return helper.numberOfRows(in: section)
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    return helper.cellForRow(at: indexPath)
}

Hide or show cells by name (if multiple cells have the same name, then all with that name are shown or hidden):

helper.hideCell("S0R0")
helper.hideCell("S0R1")
helper.showCell("S1R0")

All public methods

init(tableView:UITableView)
func addCell(section:Int, cell:UITableViewCell, name:String, isInitiallyHidden: Bool = false)

func hideInitiallyHiddenCells()
func hideCell(_ name:String)
func showCell(_ name:String)

func cellName(at indexPath:NSIndexPath) -> String?
func indexPathForCell(_ name:String) -> NSIndexPath? // first matching cell
func indexPathsForCell(_ name:String) -> [NSIndexPath]
func visibleCells(_ name:String) -> [UITableViewCell]
func cellIsVisible(_ name:String) -> Bool // // returns true if ALL cells with that name are visible

func numberOfSections() -> Int
func numberOfRows(inSection section: Int) -> Int
func cellForRow(at indexPath: NSIndexPath) -> UITableViewCell

Latest podspec

{
    "name": "TableViewHelper",
    "version": "2.1.1",
    "summary": "Easily hide and show UITableView Rows",
    "homepage": "https://github.com/AaronBratcher/TableViewHelper",
    "license": "MIT",
    "authors": {
        "Aaron Bratcher": "[email protected]"
    },
    "social_media_url": "http://twitter.com/AaronLBratcher",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/AaronBratcher/TableViewHelper.git",
        "tag": "2.1.1"
    },
    "source_files": [
        "TableViewHelper",
        "TableViewHelper/TableViewHelper/**/*.{h,m,swift}"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This