How to switch view controller programitcally

The following code cannot be changed a lot because the code is part of a nib. I just need 1 line of code that when ever cancelled is pressed the current page will be transformed back to the view controller. To go from page a to page b essentially. Right now in the code if a user hits cancel then the view controller immediately goes to the correct view controller. If the user takes a picture and then hits the cancel button. The photo is displayed and full the user can not go back to the correct view Controller.

 import Foundation
 import UIKit

 protocol OverlayViewControllerDelegate {
     func didCancel(overlayView: OverlayView)
       func didShoot(overlayView: OverlayView)
       }

class OverlayView: UIView {

@IBOutlet weak var cameraLabel: UILabel!

var delegate: OverlayViewControllerDelegate! = nil


@IBAction func cancel(_ sender: AnyObject) {

    delegate.didCancel(overlayView: self)


}

@IBAction func click(_ sender: AnyObject) {
    //cameraLabel.text = "Even Cooler Camera"
    delegate.didShoot(overlayView: self)
}


}

@zalubski Thanks very much for your question. If you’re trying to go back to the first screen, then remember that your ViewControllers are in a stack which you can get in the form of an array via the UINavigationController. Because it is the first View Controller you want to take the user to (i.e. A), then you should take the user back to this ViewController from the stack. Having said that, if the screen you want to take the user back to is simply the previous screen, then my suggestion above is overkill. What you simply need to do is using your navigation controller, simply pop the current ViewController to return the user back to where they were.

I hope this makes sense.