Created
August 18, 2015 18:42
-
-
Save jkopelioff/d2c05f3b005698105568 to your computer and use it in GitHub Desktop.
Custom segue to link storyboards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // LinkedStoryboardSegue.swift | |
| // | |
| // | |
| import UIKit | |
| class LinkedStoryboardSegue: UIStoryboardSegue { | |
| override init!(identifier: String!, source: UIViewController, destination: UIViewController) { | |
| super.init(identifier: identifier, | |
| source: source, | |
| destination: LinkedStoryboardSegue.sceneNamed(identifier)) | |
| } | |
| class func sceneNamed(identifier:String) -> UIViewController { | |
| let info = identifier.componentsSeparatedByString("@") | |
| let sceneName = info[0] | |
| let storyboardName = info[1] | |
| let storyboard = UIStoryboard(name: storyboardName, bundle: nil) | |
| var scene:UIViewController? | |
| if count(sceneName) == 0 { | |
| scene = storyboard.instantiateInitialViewController() as? UIViewController | |
| } else { | |
| scene = storyboard.instantiateViewControllerWithIdentifier(sceneName) as? UIViewController | |
| } | |
| return scene! | |
| } | |
| override func perform() { | |
| let source = self.sourceViewController as! UIViewController | |
| source.navigationController?.pushViewController(self.destinationViewController as! UIViewController, animated: true) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment