Created
May 6, 2020 09:17
-
-
Save stevencurtis/cb9d62ecf2b487e36bb950226209267d to your computer and use it in GitHub Desktop.
ViewControllerCell
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
class ViewController: UIViewController { | |
var data = ["Dave Smith", "Ahmed Khan", "Lakshmi Manchu" ,"Tom Rogers"] | |
var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
tableView = UITableView(frame: self.view.frame) | |
tableView.delegate = self | |
tableView.dataSource = self | |
let nib = UINib(nibName: "CustomTableViewCell", bundle: nil) | |
tableView.register(nib, forCellReuseIdentifier: "cell") | |
tableView.estimatedRowHeight = 44 | |
self.view = tableView | |
} | |
} | |
extension ViewController: UITableViewDataSource { | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return data.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell | |
cell.nameLabel.text = data[indexPath.row] | |
return cell | |
} | |
} | |
extension ViewController: UITableViewDelegate {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment