title: How to call method in UIPickerView subclass from another view controller?
body: <p>I have a <code>UIPickerView</code> that I am subclassing, which works great.  However, I have a method that I need to call to "reset" the UIPicker from the UIViewController in which it's being viewed.  However, it never fires.  How do I call <code>func resetPicker()</code> from another view controller?</p>
  
  <pre><code>import Foundation
  import UIKit
  
  class ScoreClockPicker: UIPickerView {
  
      //PickerView
      let timerMinutesArray = Array(00...20)
      let timerSecondsArray = Array(00...59)
      let periodArray = ["1st", "2nd", "3rd", "OT", "SO"]
  
      //Picker return values
      var numberOfRowsInComponentReturnValue = 0
      var titleForRowReturnValue             = ""
      var widthForComponentReturnValue       = ""
  
  
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
  
          self.delegate   = self
          self.dataSource = self
  
      }
  
      func resetPicker() {
          print("resetPicker")
  
          self.selectRow(0, inComponent: 0, animated: true)
          self.selectRow(0, inComponent: 1, animated: true)
          self.selectRow(0, inComponent: 3, animated: true)
  
      }
  }
  
  extension ScoreClockPicker: UIPickerViewDataSource {
  
      func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
  
          if component == 0 {
  
              numberOfRowsInComponentReturnValue =  periodArray.count
  
          } else if component == 1 {
  
              numberOfRowsInComponentReturnValue = timerMinutesArray.count
  
          } else if component == 2 {
  
              numberOfRowsInComponentReturnValue = 1
  
          } else if component == 3 {
  
              numberOfRowsInComponentReturnValue = timerSecondsArray.count
  
          }
  
          return numberOfRowsInComponentReturnValue
  
      }
  
      func numberOfComponents(in pickerView: UIPickerView) -&gt; Int {
          return 4
  
      }
  
      func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -&gt; CGFloat {
          var componentWidth = 0
  
          if component == 0 {
  
              componentWidth = 140
  
          } else if component == 1 {
  
              componentWidth = 40
  
          } else if component == 2 {
  
              componentWidth = 30
  
          } else if component == 3 {
  
              componentWidth = 40
          }
  
          return CGFloat(componentWidth)
      }
  
  
  }
  
  extension ScoreClockPicker: UIPickerViewDelegate {
  
      func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
  
          print("didSelectRow")
      }
  
      func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String? {
  
          if component == 0 {
  
              titleForRowReturnValue =  periodArray[row]
  
          } else if component == 1 {
  
              titleForRowReturnValue =  String(describing: timerMinutesArray[row])
  
          } else if component == 2 {
  
              titleForRowReturnValue =  ":"
  
          } else if component == 3 {
  
              titleForRowReturnValue =  String(format: "%02d",timerSecondsArray[row])
          }
  
          return titleForRowReturnValue
  
      }
  
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>The following doesn't work from the viewController calling the <code>ScoreClockPicker</code>:</p>
  
  <pre><code>import UIKit
  
  class ScoreClockViewController: UIViewController {
  
      @IBOutlet weak var resetButton: UIButton!
      @IBOutlet weak var okButton: UIButton!
  
     var picker: ScoreClockPicker?
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Do any additional setup after loading the view.
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
  
          //Hide the Navigation Bar
          self.navigationController?.setNavigationBarHidden(false, animated: true)
      }
  
      //@IBOutlet
      @IBAction func reset(_ sender: Any) {
          print("reset")
  
          picker?.resetPicker() //Call the ScoreClockPicker
  
  //        picker?.selectRow(0, inComponent: 0, animated: true)
  //        picker?.selectRow(0, inComponent: 1, animated: true)
  //        picker?.selectRow(0, inComponent: 3, animated: true)
      }
  
      @IBAction func ok(_ sender: Any) {
      }
  
  
  }
  </code></pre>