Why I am not able to click button and back to ViewController?

I am use SecondView as programmatically, I am click the button in ViewController and open SecondView controller, but I want to back to ViewController. I do not have storyboard in SecondView and I want to click the closeButton and back to ViewController. My code work but when I click the close button it is not work. Any idea?


import UIKit

class SecondView: UIViewController {
   

  var closeButton = UIButton()

  override func viewDidLoad() {
    super.viewDidLoad()
     
    closeButton.addTarget(self, action: #selector(dismissActionSheet), for: .touchUpInside)
  }
   
  @objc func dismissActionSheet() {
    self.navigationController?.popViewController(animated: true)
   }

}

Is it the complete code ? CloseButton is not added to the view, how do you get it on screen ? You should also define its frame.

Could you show how you transition to secondView ?

Why I am not able to click button and back to ViewController?
 
 
Q