TableViewExtension
This extension simplify registering any cell, reusing and other verbosity steps.
Install / Use
/learn @serhatsezer/TableViewExtensionREADME
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
}
}
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
