Task: I transfer a picture from one view of the controller to another. The picture is passed to the variable.

Question: Xcode asks to use the Navigator Controller before each ViewController. Therefore, we must somehow reformulate the line for getting the controller view (1 in the code)

enter image description here

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { //1 получаю вью контроллер, но ругается. **Could not cast value of type NavigationController to "Имя Вью контроллера"** let destinationVC: SaveAfterFilterScreen = segue.destinationViewController as! SaveAfterFilterScreen destinationVC.tempImage = imageFromCamera!.image! } 
  • familiar picture :) - Max Mikheyenko
  • nav controller should be one, and not one for each VC, something you messed up - Max Mikheyenko

2 answers 2

In general, I was spinning around Segue, and received the message that "UINavigationController."

After I fixed the segue Push view on modal, it worked.

  • and if you need to put another controller on top, then you will put two modal ones one by one? - Max Mikheyenko
  1. Take destinationViewController as UINavigationController.
  2. Then from this navController take topViewController as!
  3. SaveAfterFilterScreen. This will be your destinationVC

PS: exactly, instead of rootViewController you need to take topViewController. Thank you for your comment

  • And there is no such rootViewController property for UINavigationController. There are topViewController - Anatoly
  • Yes, there is no rootViewController , instead you should use .viewControllers [0] - Denis
  • it is better to take firstObject from an array - when working with an index, it is advisable to check the size of the array. PS: fixed prop on topViewController - Valentine