Search code examples
xcodeuipickerviewunit-conversion

How to change 2nd pickerview component based on 1st component selection in a pickerview?


I am working on an unit converter app. Once I input numbers to UITextLabel, pickerview will open automatically and upon choosing an option such as Feet, Yards, etc, the result will be displayed. Now, I am looking to extend this functionality for different metrics such as weight, temperature,distance,etc. So this time, I need to

  • Enter number (Working)
  • Open metrics component - Ex: Distance (working)
  • Open unit component - Ex: Feet (Stuck)
  • Display Result

Please assist how to open a unit pickerview upon choosing an option from metrics pickerview. I found a solution using UITableView UIPickerView depending on UITableView but I am trying to implement pickerview instead of UITableView.

Any help is much appreciated!


Solution

  • Okay. I got the answer. What I previously meant was a pickerview with 2 components. Upon selecting 1st component, 2nd component value must change. I made a small changes to pickerView didSelectRow where in I checked if the component is metrics, read the metrics and assign the unit array acordingly. Ex: If the metrics is temperature, assign unit array as Celsius, Farenheit,etc. Then I have reloaded all components of the pickerview. Thus the issue is resolved. Hope this helps someone.