title: Why isn't my UIBarButtonItem calling my custom function?
body: <p>I have a <code>UIViewController</code> with a <code>UIBarButtonItem</code> configured to call my custom function called <code>func settingsTapped(sender: AnyObject?)</code> in which I've put <code>performSegueWithIdentifier</code>. I've determined that this function isn't being called even though the button DOES work and the segue somehow still works because it goes to the correct view controller.</p>
  
  <p>First VC:</p>
  
  <pre><code>class CalculatorViewController: UIViewController {
  
    private let timeInterval = 0.016 //how frequently we change the displayed number
    private let animationLength = 0.3
    private var timer: NSTimer?
    private var counter: Int = 0
    private var max: Double = 0.0
    var startingPreferredUnits: String?
    @IBOutlet weak var weightLifted: UITextField!
    @IBOutlet weak var repetitions: UITextField!
    @IBOutlet weak var oneRepMax: UILabel!
    @IBOutlet weak var percentages: UITextView!
    @IBOutlet weak var units: UILabel! 
  
    override func viewDidLoad() {
  
      let settingsButton = UIBarButtonItem(title: "Settings", style: .Plain, target: self, action: #selector(settingsTapped(_:)))
  
      self.navigationItem.leftBarButtonItem = settingsButton
  
      super.viewDidLoad()
    }
  
   func settingsTapped(sender: AnyObject?) {
      startingPreferredUnits = UserDefaultsManager.sharedInstance.preferredUnits
      print("In segue, units is \(startingPreferredUnits)") // never prints this caveman debugging 
      self.performSegueWithIdentifier("segueToSettings", sender: self)
    }
  }
  </code></pre>
  
  <p>In the storyboard, I placed a Bar Button Item in the nav bar:</p>
  
  <p><a href="https://i.stack.imgur.com/hHBMq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hHBMq.png" alt="enter image description here"></a></p>
  
  <p>I created a Show (e.g. Push) segue between the Settings bar button item and the Settings view controller and I've given this segue an identifier of 'segueToSettings`. When I touch the Settings button, it does present the Settings view controller, but it doesn't print my caveman debugging line to the console.</p>
  
  <p>I also tried creating the segue between the <code>CalculatorViewController</code> itself and the <code>SettingsViewController</code> (which I think may even be a better way) but when I have it set up that way, nothing happens at all when I touch the Settings button.</p>
  
  <p>I've tried everything I could find on SO but nothing has worked. I hope I don't earn a Stupid Question badge on this one.</p>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>I'm still struggling with this one. Here's something else I've learned and tried that didn't work. Clicking the Settings button works by performing the segue from the button to the Settings page which I created in the Storyboard. As one would expect, it will call <code>override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)</code> before doing this. So it's completely ignoring the <code>action: #selector(settingsTapped(_:))</code> part. Also, I can change the identifier of the segue in the storyboard and it makes no difference at all. It still works. I can even delete the identifier and it works.</p>
  
  <p>I also tried adding another button (this time a <code>barButtonSystemItem</code> like so:</p>
  
  <pre><code> override func viewDidLoad() {
      super.viewDidLoad()
  
      let settingsButton = UIBarButtonItem(title: "Settings", style: .Plain, target: self, action: #selector(settingsTapped(_:)))
  
  let saveButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(self.saveThisLift(_:)))
  
      self.navigationItem.leftBarButtonItem = settingsButton
      self.navigationItem.rightBarButtonItem = saveButton
    }  
  
  
    func saveThisLift(sender: UIBarButtonItem) {
      print("I'm in saveThisLift") // never prints
      let weight = weightLifted.text
      let reps = repetitions.text
      let maxAmount = oneRepMax.text
      let unitsText = units.description
  
      coreDataStack.saveLiftEvent(currentLiftName!, formula: currentFormulaName!, weight: weight!, repetitions: reps!, maxAmount: maxAmount!, unitsUsed: unitsText)
  }
  
   func settingsTapped(sender: AnyObject?) {
          startingPreferredUnits = UserDefaultsManager.sharedInstance.preferredUnits
          print("In segue, units is \(startingPreferredUnits)") // never prints this caveman debugging 
          self.performSegueWithIdentifier("segueToSettings", sender: self)
        }
  </code></pre>
  
  <p>Like the Settings button, touching it does nothing except make it flash. I should point out that I added the bar button items via the storyboard and I think that's unnecessary since I'm trying to add them programmatically. However, without them, neither of the buttons appears.</p>