title: How to create UIButton action in custom class in Swift
body: <p>I want to create a class to add UIButton action, and then viewcontroller can call this class to create action.</p>
  
  <p>But the error message told me "unrecognized selector sent to instance "</p>
  
  <p>How can I fix them?</p>
  
  <pre><code>class MYController: UIViewController{
      @IBOutlet weak var pptMode: UIButton!
      @IBOutlet weak var videoMode: UIButton!
      @IBOutlet weak var meetingMode: UIButton!
      @IBOutlet weak var videoMeeting: UIButton!
      override func viewDidLoad() {
          super.viewDidLoad()
  
          ModeChange().modeChangeUtil(self,pptMode:pptMode, videoMode: videoMode, meetingMode: meetingMode, videoMeeting: videoMeeting)
  
      }
  }
  
  
  class ModeChange {
  
      func modeChangeUtil(vc:UIViewController,pptMode:UIButton,videoMode:UIButton,meetingMode:UIButton,videoMeeting:UIButton){
          pptMode.addTarget(vc, action: "modeTouched:", forControlEvents:UIControlEvents.TouchUpInside)
          pptMode.tag = modeButtonTag.ppt.rawValue
  
          videoMode.addTarget(vc, action: "modeTouched:", forControlEvents:UIControlEvents.TouchUpInside)
          videoMode.tag = modeButtonTag.video.rawValue
          meetingMode.addTarget(vc, action: "modeTouched:", forControlEvents:UIControlEvents.TouchUpInside)
          meetingMode.tag = modeButtonTag.meeting.rawValue
          videoMeeting.addTarget(vc, action:"modeTouched:", forControlEvents:UIControlEvents.TouchUpInside)
          videoMeeting.tag = modeButtonTag.videoMeeting.rawValue
  
  
      }
      enum modeButtonTag: Int {
          case ppt
          case video
          case meeting
          case videoMeeting
      }
     func modeTouched(sender:UIButton){
          let modeCmd:ModeCommand = ModeCommand(device: Mode(onoffUrl: OfficeConstants.MeetingRoom3A.MODE))
          switch sender.tag {
          case modeButtonTag.ppt.rawValue:
              modeCmd.modeStatus = .PPT
  
          case modeButtonTag.video.rawValue:
              modeCmd.modeStatus = .Video
          case modeButtonTag.meeting.rawValue:
              modeCmd.modeStatus = .Meeting
          case modeButtonTag.videoMeeting.rawValue:
              modeCmd.modeStatus = .VideoMeeting
          default: break
              //do nothing
          }
          modeCmd.execute()
      }
  }
  </code></pre>