Reputation: 11
I have 2 uipickerviews for selection of hour and minute values. When I wanted to select default values for both of them if selectedRow = 1 title color becomes gray(this means row is not selected) and this issue happens only at first load(when viewDidLoad is triggered). The colors are changed as expected except these issues.
This is my picker delegate method for changing picker label and its specifications. This function works great when I change the picker value.
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var label = UILabel()
if let v = view as? UILabel { label = v }
label.font = UIFont (name: "Muli-Bold", size: 22)
if pickerView.selectedRow(inComponent: component) == row {
label.textColor = StyleManager.colors.deviceModeActiveBlue
} else {
label.textColor = StyleManager.colors.pickerLightGray
}
if (pickerView.tag == 1){
label.text = "\(hours[row])"
}else{
label.text = "\(minutes[row])"
}
label.textAlignment = .center
return label
}
In viewDidLoad
pickerHour.selectRow(Int(calculateDelayTime(delayTime: currentDevice.dwProgramDelayDuration!)[0])!, inComponent: 0, animated: true)
pickerHour.reloadAllComponents()
pickerMinute.selectRow(Int(calculateDelayTime(delayTime: currentDevice.dwProgramDelayDuration!)[1])!, inComponent: 0, animated: true)
pickerMinute.reloadAllComponents()
When selectRow value equals 1 row title color is gray(that means this row is not selected) but first row comes selected. If its different from 1 its title color is blue(as it's supposed to be) and also selected row comes selected.
In an other saying, these two examples working as expected.
pickerHour.selectRow(2, inComponent: 0, animated: true)
pickerHour.reloadAllComponents()
pickerMinute.selectRow(2, inComponent: 0, animated: true)
pickerMinute.reloadAllComponents()
pickerHour.selectRow(0, inComponent: 0, animated: true)
pickerHour.reloadAllComponents()
pickerMinute.selectRow(0, inComponent: 0, animated: true)
pickerMinute.reloadAllComponents()
And this is not.
pickerHour.selectRow(1, inComponent: 0, animated: true)
pickerHour.reloadAllComponents()
pickerMinute.selectRow(1, inComponent: 0, animated: true)
pickerMinute.reloadAllComponents()
Thank you for your help. Have a nice day.
Upvotes: 1
Views: 84