1

I have view controller that have tableView connected to it. I present controller like that :

(in previous controller):

  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = DetailCharacterViewController()
        let characterModel = (self.viewModel.arrValues[indexPath.row] as! CharacterListItem).correspondingCharacter
        let vm = DetailCharacterViewModel(m: characterModel)
        vc.viewModel = vm
        self.navigationController?.pushViewController(vc, animated: true)
        tableView.deselectRow(at: indexPath, animated: true)
    }

But when controller appears, it crashes when try to access tableView property, that is actually:

@IBOutlet weak var tableView: UITableView!

In debug i can see that it is nil. Why?

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107

1 Answers1

1

You can use segue and func prepare to make a transition between viewControllers. Here is Apple documentation Make transition between view controllers

Arrabidas92
  • 1,113
  • 1
  • 9
  • 20