Skip to content

Instantly share code, notes, and snippets.

@karthikAdaptavant
Last active November 13, 2021 07:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthikAdaptavant/429cee20d827e39e0501c7bab046ab31 to your computer and use it in GitHub Desktop.
Save karthikAdaptavant/429cee20d827e39e0501c7bab046ab31 to your computer and use it in GitHub Desktop.
class InstrumentsViewController: UIViewController {
@IBOutlet weak var instrumentsTableView: UITableView! {
didSet {
instrumentsTableView.delegate = self
instrumentsTableView.dataSource = self
instrumentsTableView.tableFooterView = .init()
let cellNib = UINib(nibName: "InstrumentCell", bundle: .main)
instrumentsTableView.register(cellNib, forCellReuseIdentifier: "InstrumentCell")
}
}
var viewModel: InstrumentViewModel = InstrumentViewModel()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "My Portfolio"
}
}
extension InstrumentsViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.instruments.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "InstrumentCell") as! InstrumentCell
cell.instrument = viewModel.instruments[indexPath.row]
cell.configure()
return cell
}
}
extension InstrumentsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment