title: How to implement a tap gesture recognizer for multiple subviews with Swift
body: <p>I have a tableView with 3 Static Cells, each cell contains a subview with labels displaying the desired text, what I want to accomplish is to have the orientation programmatically rotate from Portrait to Landscape when the user taps on any of the 3 subviews.</p>
  
  <p>I got it working for the first subview. However, when I try to add the same Tap gesture recognizer to the other subviews it still only works for one subview. Please advise, what am I missing? Thanks for any input.</p>
  
  <p><strong>Portrait:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/1Bm2c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1Bm2c.png" alt="enter image description here"></a></p>
  
  <p><strong>Landscape</strong></p>
  
  <p><a href="https://i.stack.imgur.com/W5gto.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W5gto.png" alt="enter image description here"></a></p>
  
  <p><strong>Table View Controller code:</strong></p>
  
  <pre><code>import UIKit
  
  class SampleTableViewController: UITableViewController {
  
      @IBOutlet weak var newYorkViewWrapper: UIView!
      @IBOutlet weak var sanFranciscoViewWrapper: UIView!
      @IBOutlet weak var chicagoViewWrapper: UIView!
  
      //Vars
      let tapRec = UITapGestureRecognizer()
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          print("Sample view rendered.")
  
  
          //Tap gesture
          tapRec.addTarget(self, action: "tappedView")
          newYorkViewWrapper.addGestureRecognizer(tapRec)
          newYorkViewWrapper.userInteractionEnabled = true
          sanFranciscoViewWrapper.addGestureRecognizer(tapRec)
          sanFranciscoViewWrapper.userInteractionEnabled = true
          chicagoViewWrapper.addGestureRecognizer(tapRec)
          chicagoViewWrapper.userInteractionEnabled = true
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      //--------------------------------------------------------
      // MARK: Hide status bar
      //--------------------------------------------------------
      override func prefersStatusBarHidden() -&gt; Bool {
          return true
      }
  
      func tappedView(){
          let value = UIInterfaceOrientation.LandscapeLeft.rawValue
          UIDevice.currentDevice().setValue(value, forKey: "orientation")
      }
  
      //--------------------------------------------------------
      // MARK: View Orientation method
      //--------------------------------------------------------
      override func shouldAutorotate() -&gt; Bool {
          return true
      }
  
  
  }
  </code></pre>