gpt4 book ai didi

ios - 从另一个 pickerView 选择项目时隐藏 pickerView 的行

转载 作者:行者123 更新时间:2023-11-28 08:48:21 25 4
gpt4 key购买 nike

我创建了一个使用数组作为数据源的 UIPickerView,我想在第三个组件上选择一个项目后隐藏第四个组件上的一些项目。我该怎么做?

class ViewControllerEspessuras: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

var data = [["1.50","1.60","1.67","1.74"],
["-10.00 Esf.","-9.00 Esf.","-8.00 Esf.","-7.00 Esf.","-6.00 Esf.","-5.00 Esf.","-4.00 Esf.","-3.00 Esf.","-2.00 Esf.","-1.00 Esf.","Plano","+1.00 Esf.","+2.00 Esf.","+3.00 Esf.","+4.00 Esf.","+5.00 Esf.","+6.00 Esf.","+7.00 Esf.","+8.00 Esf.","+9.00 Esf.","+10.00 Esf."],
["1.50","1.60","1.67","1.74"],
["-10.00 Esf.","-9.00 Esf.","-8.00 Esf.","-7.00 Esf.","-6.00 Esf.","-5.00 Esf.","-4.00 Esf.","-3.00 Esf.","-2.00 Esf.","-1.00 Esf.","Plano","+1.00 Esf.","+2.00 Esf.","+3.00 Esf.","+4.00 Esf.","+5.00 Esf.","+6.00 Esf.","+7.00 Esf.","+8.00 Esf.","+9.00 Esf.","+10.00 Esf."]]

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 4
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return data[component].count
}

func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return data[component][row]
}

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let picker1 = data[0][pickerView.selectedRowInComponent(0)]
let picker2 = data[1][pickerView.selectedRowInComponent(1)]
let picker3 = data[2][pickerView.selectedRowInComponent(2)]
let picker4 = data[3][pickerView.selectedRowInComponent(3)]
}
}

Example

最佳答案

您应该更改 numberOfRowsInComponenttitleForRow forComponent 以便它们考虑第三行的选择。

之后,当第三个组件发生变化时,您可以简单地在最后一个组件上调用 reloadComponent

您可以在以下 SO 问题之一中获得更多信息:

关于ios - 从另一个 pickerView 选择项目时隐藏 pickerView 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34698705/

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