Run segue with id will not work in swift 2

I use this code to execute a custom segue when a user logs into the application:

dispatch_async(dispatch_get_main_queue()){ self.performSegueWithIdentifier("showSTPS", sender: self) } 

I currently have this code in my perpareForSegue (I'm not quite sure if I need it)

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?){ if "showSTPS" == segue.identifier { } } 

And every time I try to execute segue, I get the following error:

2015-08-31 11: 56: 28.998 ICEFLO [3858: 651041] *** Application terminated due to an uncaught exception "NSInternalInconsistencyException", reason: "Failed to execute segue with identifier" showSTPS ". Segue must either have performHandler, or he must override -perform. '

Any suggestions on what to do will be greatly appreciated - note that this is for swift2 / ios9

-Yogi

+6
source share
4 answers

Make sure your segue type is not set to custom in your storyboard. If you install it normally, you need to provide your own segue class.

+25
source

Quick version:

 class CustomSegue: UIStoryboardSegue { override func perform() { let src = self.sourceViewController let dst = self.destinationViewController src.navigationController?.pushViewController(dst, animated: true) } } 
+4
source

If segue is set to Custom, you need to override the execution method. You can follow this example .

Basically create a class that inherits from UIStoryboardSegue, for example:

MyCustomSegue.h

 @interface MyCustomSegue : UIStoryboardSegue @end 

MyCustomSegue.m

 @implementation MyCustomSegue - (void) perform { UIViewController *src = (UIViewController *) self.sourceViewController; UIViewController *dst = (UIViewController *) self.destinationViewController; [src.navigationController pushViewController:dst animated:YES]; } @end 

I think this code might work for you.

+3
source

DO NOT call super ...

 class CustomSegue: UIStoryboardSegue { override func perform() { // super.perform() NOOO or crash! let src = self.sourceViewController let dst = self.destinationViewController src.navigationController?.pushViewController(dst, animated: true) } } 
+1
source

All Articles