使用两个数字组件正确使用 UIPickerVIew

Correct work with UIPickerVIew with two numbers components

我想在第一个组件中选择数字5(例如)并希望在第二个组件中自动显示数字+1 从第一个组件中选择的数字(即六个),到第二个组件退休数字到五个(或者如果我选择另一个)。

我怎样才能正确地做到这一点?

现在我的代码是空的:

var numbers: [Int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]

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

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

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

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

}

如果我正确理解你的问题,可能是这样的

 func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
     if component == 0 {
        componentOne = numbers.filter { (a) -> Bool in
            return a > numbers[row]
        }
        pickerView.reloadComponent(1)
        pickerView.selectRow(0, inComponent: 1, animated: true)
    }
 }

并在 dataSource 方法中使用 componentOne。

我不确定你在极端情况下必须做什么,但你可以选择。