Monday, 15 June 2015

swift - How do I perform calculations with UIPickerView data? -


I need to do some calculation with selection from UIPickerView (SWIFT) I do not have any way to use an extension Is, like .floatValue to pick the string of the selected row, and convert it to a float? I have tried many different ways, and all have failed.

My selector's work is fine, and all delegates and data sources are assigned.

What do I have here:

  var spherePower: Float! Let's override data = ["-1.00", "-0.75", "-0.50", "-0.25", "0", "0.25", "0.50", "0.75", "1.00"] spherePower = // Passing the float value of the selected row here  

Your picker's data source might be storing The values ​​float in the first place, and then the representative turns that force into stars in order to display that force in the picker.

  var overRefractionData = [-1.0, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1.0] func pickerView (_ pickerView: UIPickerView, titleForRow line: Int, forComponent Component: int) - & gt; String! So when the user selects the value, you can use only the selected index to get the value from the data array:  

/ P>

  func pickerView (pickerView: UIPickerView !, DidSelectRow line: Int, Incomponent component: Int) {var selectedValue = overRefractionData [row] // Do something with the chosen value ...}  

No comments:

Post a Comment