title: Swift: Popup DatePicker on textbox with done button
body: <p>I'm creating an app that has a UITextField on it, which, when tapped / clicked, will show a Date Picker that will flyout from the bottom. Said popup panel has a Done button, which will apply whatever date is selected (default to today) to the textfield upon click / tap, of preferably YYYY-MM-DD format.</p>
  
  <p>I've been digging around the net, and so far I've seen examples with an IBAction for the textfield, with various ways as to how the done button works (and most without a done button), but I was wondering if I could recycle or base it off my code for a drop down menu below:</p>
  
  <pre><code>let wellheadPressTest : [String] = ["PSIG", "MPAG"]
  var wellboreStatusPickerView = UIPickerView()
  
  override func viewDidLoad() {
      let wellboreStatusToolBar = UIToolbar()
      let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
      let doneButtonWellbore = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: "donePickerWellbore")
  
      wellboreStatusToolBar.barStyle = UIBarStyle.Default
      wellboreStatusToolBar.translucent = true
      wellboreStatusToolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
      wellboreStatusToolBar.sizeToFit()
      wellboreStatusToolBar.setItems([spaceButton,spaceButton,doneButtonWellbore], animated: false)
      wellboreStatusToolBar.userInteractionEnabled = true
  
      wellboreStatusPickerView.delegate = self
      self.samplingWaterFormOneView.textfieldWellbore.inputView = wellboreStatusPickerView
      self.samplingWaterFormOneView.textfieldWellbore.inputAccessoryView = wellboreStatusToolBar
  }
  
  
  // Various Required PickerView functions
  
  func donePickerWellbore(){
      let row = wellboreStatusPickerView.selectedRowInComponent(0);
      pickerView(wellboreStatusPickerView, didSelectRow: row, inComponent:0)
      self.samplingWaterFormOneView.textfieldWellbore.resignFirstResponder()
  }
  </code></pre>
  
  <p>Here's what I tried:</p>
  
  <pre><code>var dateSampledPickerView = UIDatePicker()
  
  override func viewDidLoad() {
      let dateSampledPickerToolBar = UIToolbar()
      let doneButtonDate = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: "donePickerDate")
      dateSampledPickerToolBar.barStyle = UIBarStyle.Default
      dateSampledPickerToolBar.translucent = true
      dateSampledPickerToolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
      dateSampledPickerToolBar.sizeToFit()
      dateSampledPickerToolBar.setItems([spaceButton,spaceButton,doneButtonDate], animated: false)
      dateSampledPickerToolBar.userInteractionEnabled = true
  
      dateSampledPickerView.datePickerMode = UIDatePickerMode.Date
      dateSampledPickerView.addTarget(self, action: Selector("datePickerValueChanged"), forControlEvents: UIControlEvents.ValueChanged)
  
      self.samplingWaterFormOneView.textfieldDateSampled.inputView = dateSampledPickerView
      self.samplingWaterFormOneView.textfieldDateSampled.inputAccessoryView = dateSampledPickerToolBar
      self.samplingWaterFormOneView.textfieldDateSampled.delegate = self
  }
  
  func datePickerValueChanged(sender:UIDatePicker) {
      let dateFormatter = NSDateFormatter()
      dateFormatter.dateStyle = "YYYY-MM-DD"
      dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle
      self.samplingWaterFormOneView.textfieldDateSampled.text = dateFormatter.stringFromDate(sender.date)
  }
  
  func donePickerDate(){
      self.samplingWaterFormOneView.textfieldDateSampled.resignFirstResponder()
  }
  </code></pre>
  
  <p>My code above does show a pop-up menu with a date picker when I top the textfield, with a done button, but the textfield doesn't get the date.</p>
  
  <p>EDIT: Also tried modifying the <code>datePickerValueChanged</code> such that it doesn't have a sender, and also uses the <code>dateSampledPickerView</code> for the textfield. Didn't work.</p>
  
  <p>Putting in comments in the function suggests that the <code>datePickerValueChanged</code> function isn't being called.</p>
  
  <p>What am I doing wrong?</p>