Create your navigation bar item in ViewControllerA like this:
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .Plain, target: self, action: "nextViewController")
}
Create a function in ViewControllerA to handle the touch event and navigate to ViewControllerB:
func nextViewController() {
println("go next")
//TODO: get an instance of your ViewControllerB here...
//navigate to it
self.navigationController!.pushViewController(viewControllerB, animated: true)
}
How you get an instance of your ViewControllerB depends on how you defined it. If it's in your Main.storyboard, you can do this:
let viewControllerB = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewControllerB") as? ViewControllerB
This requires you to set the Storyboard ID for your ViewControllerB to "ViewControllerB". Do this by selecting it in your storyboard and going to Identity inspector.
If your ViewControllerB is defined in a nib with the same name, do this:
let viewControllerB = ViewControllerB(nibName: "ViewControllerB", bundle: nil)
If your ViewControllerB is defined entirely in code, this should work to get an instance of it:
let viewControllerB = ViewControllerB()