Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIPickerView在错误的组件中选择行(需要驱魔?)_Ios_Swift_Uipickerview - Fatal编程技术网

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

Ios UIPickerView在错误的组件中选择行(需要驱魔?),ios,swift,uipickerview,Ios,Swift,Uipickerview,我不知道我做了什么来激怒众神,但我的UIPickerView行为异常。它有两个组件,分别表示月份和年份值,选择右侧组件(年份)上的值会导致左侧组件(月份)也更改值 我最初使用以下代码创建UIPickerView: pickerView = UIPickerView(frame: ...) pickerView.delegate = self pickerView.dataSource = self 然后,我实现了一些简单的委托/数据源方法来处理选择器视图,如下所示: func pickerVi

我不知道我做了什么来激怒众神,但我的UIPickerView行为异常。它有两个组件,分别表示月份和年份值,选择右侧组件(年份)上的值会导致左侧组件(月份)也更改值

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

pickerView = UIPickerView(frame: ...)
pickerView.delegate = self
pickerView.dataSource = self
然后,我实现了一些简单的委托/数据源方法来处理选择器视图,如下所示:

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
}
此外,即使我没有设置picker视图的数据源,也会调用UIPickerView数据源方法
numberOfComponents


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

这是iOS模拟器中的一个bug,因为在我的iPhone上运行它时,它就像一个符咒。我还以为我在那里会发疯呢


我将在早上提交一个bug投诉…祝其他人好运

您的
expirationMonth
expirationYear
ivar上是否有
didSet
?@duncac否,它们仅通过上述方法更改。@duncac原来是一个iOS模拟器错误。我可以确认我在模拟器中遇到了相同的问题,但不是在我的手机上。我在模拟器上也有同样的问题,在真实的设备上运行良好