Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created February 5, 2023 21:25
Show Gist options
  • Select an option

  • Save foxicode/8eedf6088454a5c2298f3ef9107cb4b3 to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/8eedf6088454a5c2298f3ef9107cb4b3 to your computer and use it in GitHub Desktop.
Contacts adapter
import UIKit
class ContactsAdapter: NSObject, UITableViewDelegate, UITableViewDataSource {
var contacts = [Contact]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
contacts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: ContactCell.cellId, for: indexPath)
if let contactCell = cell as? ContactCell {
contactCell.setContact(contacts[indexPath.row])
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
// TODO: Open contact info
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
156
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment