I'm having trouble finding help on performing a segue, or some kind of view transition with swift with at least iOS 8 or later. I'm trying to avoid using the Storyboard editor as much as possible, aside from implementing a segue from the Main View Controller to the xib.
This is what I have so far:
let bundle = NSBundle(forClass: self.dynamicType)
let secondViewController = ViewController(nibName: "SwitchRegionSegue", bundle: nil)
self.presentViewController(secondViewController, animated: true, completion: nil)
The code above is called from the main ViewController.swift using the Single View Application new project scaffold. But it results in a crash:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SwitchRegionSegue" nib but the view outlet was not set.'
I also have these two files like so:
SwitchRegionSegue.xib
SwitchRegionSegue.swift
I've made sure that the file's owner custom class for the xib is set to SwitchRegionSegue : UIView
My SwitchRegionSegue.swift is just a blank canvas and looks like this:
import UIKit
class SwitchRegionSegue: UIView {
var view: UIView!
var nibName = "SwitchRegionSegue"
func xibSetup() {
view = loadViewFromNib()
// use bounds not frame or it'll be offset
view.frame = bounds
// Make the view stretch with containing view
view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
addSubview(view)
}
func loadViewFromNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: nibName, bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}
}
Anyone know what it is that I'm not doing correctly here? (suggestion to a good swift & xib textbook would be awesome)