The Wayback Machine - https://web.archive.org/web/20201102182327/https://github.com/serhatsezer/TableViewExtension
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 

README.md

TableViewExtension

When we are working with UITableView with code or Nibs we always have to write lots of code for to tableview do its job. This extension helps you write more swifty way to do so.

Usage

You can register a UITableViewCell, HeaderFooterView as simple as like;

tableView.reuse(CustomTableViewCell.self, fromNib: true) // fromNib is a optional. Default value is false.

You can use this method to dequeue your cell or header view;

tableView.dequeue(indexPath, fromNib: true)

Here is full the implementation

class ViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView
            .reuse(InfoCell.self) // Without nib file
            .reuse(CustomTableViewCell.self, fromNib: true) // With nib file
            .registerHeaderFooter(HeaderView.self, fromNib: true)
    }
}

extension ViewController: UITableViewDelegate, UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        if indexPath.row % 2 == 0 {
            let infoCell: InfoCell = tableView.dequeue(indexPath)
            return infoCell
        } else {
            let secondCell: SecondTableViewCell = tableView.dequeue(indexPath, fromNib: true)
            return secondCell
        }
    }
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let sectionHeaderView: HeaderView? = tableView.dequeueHeaderFooter(fromNib: true)
        
        return sectionHeaderView
    }
}

About

This extension simplify registering any cell, reusing and other verbosity steps.

Topics

Resources

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.