Reputation:
I have programmed a UICollectionView and when the cell is select I would like for it to go to another view cotroller. I am getting the error message of
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value.
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "twoVC") as? twoVC
self.navigationController?.pushViewController(vc!, animated: true)
//Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
}
}
class twoVC : UIViewController {
@IBOutlet var label : UILabel!
@IBOutlet var photo : UIImageView!
}
Upvotes: 0
Views: 56
Reputation: 12832
You are force unwrapping vc
so chances are that it is nil
which means that likely "twoVC"
is not the identifier for that view controller in the storyboard. Double check that in your storyboard:
Upvotes: 3