gpt4 book ai didi

ios - UIPickerView 在错误的组件中选择行(需要驱魔?)

转载 作者:搜寻专家 更新时间:2023-11-01 06:27:32 24 4
gpt4 key购买 nike

我不知道我做了什么惹怒了众神,但我的 UIPickerView 行为异常。它有 2 个组件,用于月值和年值,在右侧组件(年)上选择一个值会导致左侧组件(月)也更改值。

我最初使用以下代码创建 UIPickerView:

pickerView = UIPickerView(frame: ...)
pickerView.delegate = self
pickerView.dataSource = self

然后我实现了一些简单的委托(delegate)/数据源方法来处理选择器 View ,如下所示:

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if component == 0 {
expirationMonth = months[row]
} else {
expirationYear = years[row]
}
expirationTextField?.text = "\(expirationMonth ?? "")/\(expirationYear?.substring(from: 2) ?? "")"
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if component == 0 {
return months[row]
} else {
return years[row]
}
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if component == 0 {
return months.count
} else {
return years.count
}
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}

此外,即使我没有设置选取器 View 的数据源,UIPickerView 数据源方法 numberOfComponents 也会被调用。

我不知道是什么导致了这种行为。我已经尝试了几乎所有的方法,但没有什么能阻止它改变两列的值。有没有人有解决这个问题的想法?

最佳答案

事实证明这是 iOS 模拟器中的一个错误,因为在我的 iPhone 上运行它时它运行得非常好。我以为我在那里发疯了一秒钟!

我打算在早上提交错误投诉...祝其他遇到此问题的人好运。

关于ios - UIPickerView 在错误的组件中选择行(需要驱魔?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52030186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com