Hadeel
Hadeel

Reputation: 31

Swift 3 can't pass variable from tableView to detailView

I am trying to pass the cell name to next view (detailView) but always get this error "fatal error: unexpectedly found nil while unwrapping an Optional value" enter image description here

Upvotes: 0

Views: 73

Answers (1)

dalton_c
dalton_c

Reputation: 7171

At the time that prepare(for segue... is called, your outlets have not been assigned yet. Your view must be loaded before your outlets are assigned. You can force the view to load simply by accessing it (detailView.view), but this is a bad idea. A better approach would be to assign another property on your view controller with the value you're trying to pass around, then in viewDidLoad of your detail view controller, set the properties you wish to set on your IBOutlets.

Upvotes: 3

Related Questions