Good day to all,
I tried explaining my query in the subject line. As I understand and from what I see in the code, all pickerviews are initialized in ViewDidLoad(), which means that all have their data set. As part of my data validation, which in this case is extremely important, I want to set the following pickerviews according to the previous ones selection.
Where I get stuck is to populate the following pickerview's titles with the 'new' data and reloading the view.
Ideally I would like the views to appear as previous selections are made.
If you know how to do this logically please let me know, I will appreciate any help I can get at the moment!
I'm not really sure what you mean by logically, but you just use if statements and switches to determine what's been selected and what to present based on that selection. Then you reload the data.
func pickerView(pickerView: UIPickerView,
didSelectRow row: Int,
inComponent component: Int)
{
if component == 0
{
switch row{
case 0:
self.titlesForComponentOne = ["One","Two","Three","Four"]
case 1:
self.titlesForComponentOne = ["One","Two"]
default:
self.titlesForComponentOne = ["One","Three","Four"]
}
}else if component == 1
{
switch row{
case 0:
self.titlesForComponentTwo = ["Three", "Four"]
case 1:
….
self.picker.reloadAllComponents() // or just ones that need to be updated
}
func pickerView( pickerView: UIPickerView,
numberOfRowsInComponent component: Int) -> Int
{
switch component{
case 0:
return self.titlesForComponentZero.count
case 1:
return self.titlesForComponentOne.count
case 2:
….
}