gfd
gfd

Reputation: 37

SWIFT 3: Segue with navigation controller

I'm trying to send some values from one viewcontroller to another. (all embedded in NavigationController). I could make segue with normals viewcontrollers so in general I understand a segue idea. I've to do that in two different ways and got two different problems.

First way, segue does right but "two times". I mean after segue (which I want) there is another segue to same controller but without navigation controller and without data I would send. The "back" button on last viewcontroller is returning to AlmostViewController.

Here's code: enter image description here

Second way, Nothing happened,

ErorCould not cast value of type 'RevisionApp.AlmostViewController' (0x1055d58c0) to 'UINavigationController' (0x107669f18).

Here's code: enter image description here

Upvotes: 2

Views: 2166

Answers (3)

BhuShan PaWar
BhuShan PaWar

Reputation: 79

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("ViewController2") as NextViewController self.presentViewController(nextViewController, animated:true, completion:nil)

Upvotes: 0

Rukshan
Rukshan

Reputation: 8066

Problem is line number 18. You are trying to cast AlmostViewController to a UINavigationController. Directly access like this,

let detailController = segue.destination as! AlmostViewController

Upvotes: 0

Abhishek Biswas
Abhishek Biswas

Reputation: 1263

For the first Problem, When using embedded in navigation controller you have don't have to create action function when the button is tapped. Navigation controller does it for you. So things you need to do :

  1. Disconnect the function btnTapped from the button using storyBoard.
  2. Delete or comment the function btnTapped(You don't need it).

Upvotes: 0

Related Questions