Reputation: 211
I've set up a picker to draw from 2 different arrays, depending on which units the user wants to use. Everything works fine, but after flipping the switch, the user must move the picker through several values before the display is updated to show the new units. Am I going about this the wrong way? Should I have 2 separate pickers with a boolean to switch alphas on and off?
I was hoping there would be a simple way to force the picker to jump 5 rows ahead or back, which should update the entire display to the new units, but I can't find a way to do this. Any direction would be greatly appreciated.
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
let flatKComp = 0
var formattedFlatK : String!
var formattedSteepK : String!
if dioptorsOn == true
{ // linked to a UISwitch
formattedFlatK = String(format: "%.2f", flatKArrayD[row])
formattedSteepK = String(format: "%.2f", steepKArrayD[row])
if component == flatKComp
{
return formattedFlatK
}
else
{
return formattedSteepK
}
}
else
{
formattedFlatK = String(format: "%.2f", flatKArrayMM[row])
formattedSteepK = String(format: "%.2f", steepKArrayMM[row])
if component == flatKComp
{
return formattedFlatK
}
else
{
return formattedSteepK
}
}
}
Upvotes: 0
Views: 612
Reputation: 11435
Have you tried refreshing the pickerView
using:
pickerView.reloadAllComponents()
Upvotes: 2