Instead of assigning the view controller as the UITableViewDelegate
, I'm trying to reduce the code in the view controller by creating an extension for the UITableViewDelegate
.
Why am I getting the error "Use of unresolved identifier companyDetailVC" for the line companyDetailsVC = CompanyDetailsViewController()
when that is correct Swift 3 syntax?
Code
extension TableViewDelegate: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
companyDetailsVC = CompanyDetailsViewController()
self.present(companyDetailsVC, animated: true, completion: nil)
}
}
Edit: I'm trying to do this programmatically without storyboard. I created a UITableViewDelegate
extension because I'm trying to reduce the code in the View Controller.
Replace your code with below code. You will need to provide your ViewController to create its extension and to use the property and method of it.
Make sure companyDetailsVC is declared in the controller. You don't need to use self until its called from block.
extension yourViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.companyDetailsVC = CompanyDetailsViewController()
self.present(companyDetailsVC, animated: true, completion: nil)
}
}