Xcode where to assign segue id

Excuse me for the initial question in Swift 2. I know I can switch to another screen (ViewController) like this

self.performSegueWithIdentifier ("SecondViewController", sender: self) 

but I can’t find where to assign my second screen id, I just found the ID of the storyboard, is that it?

I already tried, just got a crash with the following error:

 'Receiver (<MyApps.RegViewController: 0x7fda5ae3abf0>) has no segue with identifier 'SecondViewController'' 

Any idea? thanks

+4
ios xcode swift uistoryboard uistoryboardsegue
source share
3 answers

The Segue identifier is not the same as the storyboard identifier, the storyboard identifier used when you want to create a viewController based on this particular storyboard - and it must be unique, unlike the segue identifier -.

If you already know how to create a segue, you can skip this part.

Adding a segue between two viewControllers:

In the interface builder, press ctrl and drag between the two view managers you want to link. You should see:

enter image description here

Select Show -for example-, the output should look like this:

enter image description here

The arrow surrounded by the red rectangle is segue.

addtional note: if you selected "show", you have your first viewController built in to the navigationController (select your first viewController -> Editor -> Embed In -> Navigation Controller), the result should look like this:

enter image description here

Identifier assignment for a segment:

Select segue, from the attribute inspector you will see the "Identifier" text box so that it! be sure to insert the same name as in performSegueWithIdentifier .

If you do not know where to find the attribute inspector, it is in the upper right form:

enter image description here


AND

To add several segues from one viewController to many, perform the same process (ctrl + drag from the first controller to another viewController), the output should look like this:

enter image description here

In this case, you may run into the problem of how to recognize which session was performed, overriding the prepareForSegue method is a solution, you can do a check based on the segue identifier:

 override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { if (segue.identifier == "firstSegueIdentifier") { // ... } else if (segue.identifier == "secondSegueIdentifier") { //... } } 
+15
source share

When you link the View controller to another View controller in the storyboard, in connection with them you need to assign the identifier segue ie "SecondViewController", only then your code will work.

Alternatively, you can also show another view controller using the storyboard identifier using self.storyboard.instantiateViewControllerWithIdentifier ("// the storyboard identifier of this view controller"), and then either use the current / show view controller.

0
source share

In your code

 self.performSegueWithIdentifier ("SecondViewController", sender: self) 

the line "SecondViewController" looks like a storyboard identifier. In the same place you need to write the segue identifier, not the storyboard identifier.

Follow the screen and name the segue identifier by clicking on the segue field in the upper right field. You can do it

 self.performSegueWithIdentifier ("WriteSegueIdentifierName", sender: self) 

enter image description here

0
source share

All Articles