Last active
November 13, 2021 07:49
-
-
Save karthiikmk/429cee20d827e39e0501c7bab046ab31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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