ios - UIPickerView 选定的行标题设计在行值等于 1 时未更改
问题描述
我有 2 个用于选择小时和分钟值的 uipickerviews。当我想为它们选择默认值时,如果 selectedRow = 1 标题颜色变为灰色(这意味着未选择行)并且此问题仅在第一次加载时发生(触发 viewDidLoad 时)。除了这些问题,颜色按预期更改。
这是我用于更改选择器标签及其规范的选择器委托方法。当我更改选择器值时,此功能非常有用。
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
}
在 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()
当 selectRow 值等于 1 时,行标题颜色为灰色(这意味着该行未被选中)但第一行被选中。如果它与 1 不同,则其标题颜色为蓝色(应该是蓝色),并且选中的行也被选中。
换句话说,这两个示例按预期工作。
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()
这不是。
pickerHour.selectRow(1, inComponent: 0, animated: true)
pickerHour.reloadAllComponents()
pickerMinute.selectRow(1, inComponent: 0, animated: true)
pickerMinute.reloadAllComponents()
谢谢您的帮助。祝你今天过得愉快。
解决方案
推荐阅读
- javascript - 本地存储在重新加载时不返回文本
- javascript - R闪亮:使用闪亮材料以编程方式切换标签
- javascript - Mongodb:如何将函数链接在一起并获得结果?
- facebook - 在 Flutter 应用中,有没有办法将图像和文本分享到 Facebook 群组?
- c - 为什么这段代码用 clang 而不是 gcc 编译?我正在学习 C 中的不透明结构
- jasper-reports - 如何根据 SQL 中的分组数据在 jasper 报告中重复表格
- google-sheets - 检查行中的值是否存在于同一行的其他列中
- python - 为什么 sklearn cross_validate() 改装?
- qt - QML - GridLayout - 无法使用它来居中页面
- symfony - 未找到 ID id(45) 的“App\Entity\Slider”类型实体