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

时间:2016-01-09 20:44:02

标签: ios swift uipickerview

我使用数组作为我的数据源创建了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

1 个答案:

答案 0 :(得分:0)

您应该更改numberOfRowsInComponent e titleForRow forComponent,以便他们考虑第三行的选择。

之后,只需更改第三个组件,就可以在最后一个组件上调用reloadComponent

您可以通过以下SO问题获得更多信息: