Skip to content

Instantly share code, notes, and snippets.

@jkopelioff
Created August 18, 2015 18:42
Show Gist options
  • Select an option

  • Save jkopelioff/d2c05f3b005698105568 to your computer and use it in GitHub Desktop.

Select an option

Save jkopelioff/d2c05f3b005698105568 to your computer and use it in GitHub Desktop.
Custom segue to link storyboards
//
// 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