Skip to content

Instantly share code, notes, and snippets.

@iranjith4
Last active November 23, 2018 09:28
Show Gist options
  • Save iranjith4/069adeb17aab09a5ed0ed5948bc3db9f to your computer and use it in GitHub Desktop.
Save iranjith4/069adeb17aab09a5ed0ed5948bc3db9f to your computer and use it in GitHub Desktop.
reusableview-registering-in-viewcontroller
/// Registering for UITableView
myTableView.register(MyCustomTableViewCell.self)
myTableView.register(MyCustomHeaderFooterView.self)
/// Registering for UICollectionView
myCollectionView.register(MyCustomCollectionViewCell.self)
myCollectionView.register(MyCollectionViewReusableView.self)
/// Dequeueing in the cellForRowAt / viewForFooter etc.
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: MyCustomTableViewCell = tableView.dequeueReusableCell(for: indexPath)
return cell
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = tableView.dequeueReusableHeaderFooterView(MyCustomHeaderFooterView.self)
return footerView
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment