Get Ready For Segue In Swift

I came across an error message:

"UIStoryboardSegue does not have a member named 'identifier'" 

Here is the code causing the error

 if (segue.identifier == "Load View") { // pass data to next view } 

In Obj-C, it works fine as follows:

 if ([segue.identifier isEqualToString:@"Load View"]) { // pass data to next view } 

What am I doing wrong?

+60
ios swift uistoryboard uistoryboardsegue
Jun 04 '14 at
source share
10 answers

This is due to a problem in the template subclass of UITableViewController . It comes with a version of the prepareForSegue method, which would require you to deploy segue.

Replace the current prepareForSegue function with:

 override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { if (segue.identifier == "Load View") { // pass data to next view } } 

This version implicitly expands the parameters, so you should be fine.

+97
Jun 04 '14 at 15:02
source share
— -

Swift 4, Swift 3

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "MySegueId" { if let nextViewController = segue.destination as? NextViewController { nextViewController.valueOfxyz = "XYZ" //Or pass any values nextViewController.valueOf123 = 123 } } } 
+37
Oct 03 '16 at 18:44
source share

I think the problem is what you should use! split id

I have

 override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) { if segue!.identifier == "Details" { let viewController:ViewController = segue!.destinationViewController as ViewController let indexPath = self.tableView.indexPathForSelectedRow() viewController.pinCode = self.exams[indexPath.row] } } 

I understand that without! you just get true or false value

+36
Jun 04 '14 at
source share

For Swift 2.3, swift3, and swift4:

Create a Segue Performance on didSelectRowAtindexPath

For example:

  self.performSegue(withIdentifier: "uiView", sender: self) 

After that, create the prepareforSegue function to catch the Destination transition and pass the value:

Example:

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "uiView"{ let destView = segue.destination as! WebViewController let indexpath = self.newsTableView.indexPathForSelectedRow let indexurl = tableDatalist[(indexpath?.row)!].link destView.UrlRec = indexurl //let url = } } 

You need to create a variable called UrlRec in the Destination ViewController

+11
Nov 28 '16 at 10:18
source share

Swift 1.2

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if (segue.identifier == "ShowDeal") { if let viewController: DealLandingViewController = segue.destinationViewController as? DealLandingViewController { viewController.dealEntry = deal } } } 
+10
Mar 31 '15 at 5:01
source share

Get ready for Segue in Swift 4.2 and Swift 5.

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if (segue.identifier == "OrderVC") { // pass data to next view let viewController = segue.destination as? MyOrderDetailsVC viewController!.OrderData = self.MyorderArray[selectedIndex] } } 

How to trigger a transition to a specific event (for example, pressing a button, etc.):

 performSegue(withIdentifier: "OrderVC", sender: self) 
+2
Aug 21 '19 at 6:46
source share

This is one of the ways you can use this function when you want to access a variable of another class and change the output based on this variable.

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) { let something = segue.destination as! someViewController something.aVariable = anotherVariable } 
+1
Dec 09 '17 at 21:08
source share

Provided that you are not using the same destination view controller with different identifiers, the code may be shorter than other solutions (and some other answers don't use as! ):

 override func prepare(for segue: NSStoryboardSegue, sender: Any?) { if let myViewController = segue.destinationController as? MyViewController { // Set up the VC } } 
0
Jun 14 '18 at 15:55
source share

Change the segue id in the right pane in the id section. An icon that matches the string that you used in the conditional expression.

-one
Feb 20 '16 at 5:26
source share
 override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) { if(segue!.identifier){ var name = segue!.identifier; if (name.compare("Load View") == 0){ } } } 

You cannot compare id with ==, you have to use compare () method

-3
Jun 11 '14 at 18:26
source share



All Articles