Hide Rows from a pickerview when selecting an item from another pickerview - Swift

Asked

Viewed 53 times

0

I created a pickerview using a multidimensional array, I would need to hide some items from picker4 after I selected the first item of picker3.

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."]]
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    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 answer

0

You must change your numberOfRowsInComponent and titleForRow forComponent so that they take into account the selection of the third party.

Done that’s just calling reloadComponent of the last when the third changes.

References can be found in that OS response (in English)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.