title: How to add action to UIBarButtonItem which is created by storyboard in swift?
body: <p>Create a <code>UIBarButtonItem</code> which name is <code>nextVc</code> on my <code>navigationBar</code>, and set its action by <code>nextVc.action = #selector(self.gotoVC4)</code>, but it does not work.</p>
  
  <p>my code is below:</p>
  
  <pre><code>    class ViewController3: UIViewController {
  
      @IBOutlet weak var nextVc: UIBarButtonItem!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          nextVc.action = #selector(self.gotoVC4)
  
      }
  
      func gotoVC4() -&gt; Void {
  
  
          print("go to vc4")
  
          let vc4 = ViewController4()
          self.navigationController!.pushViewController(vc4, animated: true)
  
      }
  
  
  }
  </code></pre>
  
  <p>and the image of storyboard is here:</p>
  
  <p><a href="https://i.stack.imgur.com/nTYGy.png" rel="nofollow"><img src="https://i.stack.imgur.com/nTYGy.png" alt="the storyboard shootscreen"></a></p>