title: UIButton unrecognized selector sent to instance when using code in new ViewController
body: <p>I've started building a very simple app which has two screens. The first has two UIbuttons. One button plays a random sound using the code below in my first view controller (ViewController.swift) and the other button modally presents a second screen.</p>
  
  <p>On the second screen there are also two UIbuttons one to play another random sound and the other to go back to the first screen.</p>
  
  <p>Playing a random sound on the first screen works perfectly.</p>
  
  <p>For the second screen I have created a brand new ViewController called PageOneViewController.swift and made sure that the class is assigned correctly in IB. This second view controller contains a carbon copy clone of the code from the second page except with changes in names to avert conflict and confusuion. However any attempt to play a sound on this second page results in a Unrecognized Selector error and I cannot figure out why.</p>
  
  <p>The error message is as follows: </p>
  
  <pre><code>2016-10-17 18:04:57.749 NewApp[28750:2719569] *** Terminating app     due to uncaught exception 'NSInvalidArgumentException', reason: '-    [NewApp.PageOneViewController buttonPressed2WithSender:]: unrecognized     selector sent to instance 0x7fe79070b8a0'
  </code></pre>
  
  <p>And it stops on this line (which I realise isn't much help):</p>
  
  <pre><code>class AppDelegate: UIResponder, UIApplicationDelegate {
  </code></pre>
  
  <p>I am connecting the buttons manually via the inspector and using 'Touch Up Inside" as the touch method.</p>
  
  <p>I cannot get my head around this at all. In the good old Objective-C days I would run into this issue when I'd named a file incorrectly or one of the sound files was missing from the bundle but I've checked everything over and over again and cannot work out whats going on. </p>
  
  <p>Code for ViewController.swift:</p>
  
  <pre><code>import AVFoundation
  import UIKit
  
  class ViewController: UIViewController {
  
      @IBOutlet weak var mainButton1: UIButton!
  
      var arrayOfSounds = ["1", "2", "3", "4", "5", "6", "7", "8", "9",     "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",     "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",     "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44",
                           "45", "46", "47", "48", "49", "50", "51" ,     "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63",     "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75",     "76", "77", "78", "79", "80", "81", "82"]
      var audioPlayer : AVAudioPlayer?
  
      func setupAudioPlayer(file: NSString, type: NSString){
          let path = NSBundle.mainBundle().pathForResource(file as     String, ofType: type as String)
          let url = NSURL.fileURLWithPath(path!)
          do {
              try  audioPlayer =  AVAudioPlayer(contentsOfURL: url)
          } catch {
              print("Player not available")
          }
      }
  
      @IBAction func buttonPressed(sender: AnyObject){
              let range: UInt32 = UInt32(arrayOfSounds.count)
              let number = Int(arc4random_uniform(range))
  
      self.setupAudioPlayer(arrayOfSounds[number], type: "wav")
      self.audioPlayer?.play()
  
  
  
  
  }
  }
  </code></pre>
  
  <p>Code for PageOneViewController.swift:</p>
  
  <pre><code>import AVFoundation
  import UIKit
  
  class PageOneViewController: UIViewController {
  
      @IBOutlet weak var mainButtonNew: UIButton!
  
      var arrayOfSounds = ["1", "2", "3", "4", "5", "6", "7", "8", "9",     "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",     "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",     "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44",
                           "45", "46", "47", "48", "49", "50", "51" ,     "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63",     "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75",     "76", "77", "78", "79", "80", "81", "82"]
      var audioPlayer : AVAudioPlayer?
  
      func setupAudioPlayer(file: NSString, type: NSString){
          let path = NSBundle.mainBundle().pathForResource(file as     String, ofType: type as String)
          let url = NSURL.fileURLWithPath(path!)
          do {
              try  audioPlayer =  AVAudioPlayer(contentsOfURL: url)
          } catch {
              print("Player not available")
          }
      }
  
      @IBAction func buttonPressedNew(sender: AnyObject){
              let range: UInt32 = UInt32(arrayOfSounds.count)
              let number = Int(arc4random_uniform(range))
  
      self.setupAudioPlayer(arrayOfSounds[number], type: "wav")
      self.audioPlayer?.play()
  
  
  
  
  }
  }
  </code></pre>