Last active
May 8, 2018 08:04
-
-
Save shankartshinde/34a1bb6c0195e320d56418ef74161ae9 to your computer and use it in GitHub Desktop.
How to register a cell for UITableViewCell reuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cellIdentifier = "CellIdentifier" | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellIdentifier) | |
} | |
OR | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "DefaultCell")! | |
return cell | |
} | |
The other option is to use register() with an Interface Builder nib file, like this: | |
tableView.register(UINib(nibName: "yourNib", bundle: nil), forCellReuseIdentifier: "CellFromNib") | |
// Register table cell class from nib | |
let cellNib = UINib(nibName: "TableCellNib", bundle: bundle) | |
self.tableView.registerNib(cellNib, forCellReuseIdentifier: self.tableCellId) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Register table cell class from nib
let cellNib = UINib(nibName: "TableCellNib", bundle: bundle)
self.tableView.registerNib(cellNib, forCellReuseIdentifier: self.tableCellId)