Last active
November 23, 2018 09:28
-
-
Save iranjith4/069adeb17aab09a5ed0ed5948bc3db9f to your computer and use it in GitHub Desktop.
reusableview-registering-in-viewcontroller
This file contains 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
/// 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