title: Swift: how to show UIPickerView when a UITextField is tapped
body: <p>In My iOS app there is a table where some cells contain a UITextField and I would like when that UITextField is tapped then its UIPiCkerView is selected and, after the selection the UIPickerView should disappear. Following <a href="https://stackoverflow.com/questions/26819423/show-uipickerview-text-field-is-selected-then-hide-after-selected">this</a> tutorial I have written the following class representing a cell with a picker view:</p>
  
  <pre><code>import Foundation
  import UIKit
  
  class PickerCell: UITableViewCell, UIPickerViewDataSource,UIPickerViewDelegate, UITextFieldDelegate {
  @IBOutlet weak var label : UILabel!
  @IBOutlet var myPicker: UIPickerView! = UIPickerView()
  @IBOutlet weak var selectedData: UITextField!
  
  var pickerData:[String]!
  
  func numberOfComponentsInPickerView(pickerView: UIPickerView) -&gt; Int {
      return 1
  }
  
  func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
      return pickerData.count
  }
  
  func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String! {
      return pickerData[row]
  }
  
  func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
      self.selectedData.text = self.pickerData[row]
      self.myPicker.hidden = true;
  }
  
  
  func configurePickerCell(labelText:String, enabled:Bool, defaultValueIndex:Int) {
      self.label.text = labelText
  
      var labelFrame:CGRect = self.label.frame
      labelFrame.size.height = Settings.labelHeight
      self.label.frame = labelFrame
  
      self.myPicker.delegate = self
      self.myPicker.dataSource = self
      self.selectedData.delegate = self
  
      self.setEditable(enabled)
  
  }
  
  func setEditable(canEdit:Bool) {
  
      if (canEdit) {
          self.selectedData.userInteractionEnabled = true
          self.label.highlighted = false
          self.selectedData.layer.borderColor = UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1).CGColor
  
      }
      else {
          self.selectedData.userInteractionEnabled = false
          self.label.highlighted = true
          self.selectedData.layer.borderColor = UIColor(red: 176/255, green: 176/255, blue: 176/255, alpha: 1).CGColor
      }
  
  }
  
  func textFieldShouldBeginEditing(textField: UITextField) -&gt; Bool {
      self.myPicker.hidden = false
      return false
  }
  
  
  }
  </code></pre>
  
  <p>but I think I am missing something because when I tap on the UITextView the UIPickerView does not appear but the cursor is showed inside it. What am I missing?</p>