I have 2 pickers in 1 VC and know that this should be handled by using if else to identify which delegate methods each should follow. However Im new to getting my head around this and im not sure what i should be returning on my methods in order to have them work correctly.
Here is the code, I have just used 0 and "" to prevent code errors for now until I can get the correct returns sorted out.
func numberOfComponents(in pickerView: UIPickerView) -> Int {
if pickerView == repsPicker {
return 1
} else if pickerView == setsPicker {
return 1
}
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView == repsPicker {
return repPickerValues.count
} else if pickerView == setsPicker {
return self.setsPickerValues.count
}
return 0
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView == repsPicker {
return repPickerValues[row]
} else if pickerView == setsPicker {
return self.setsPickerValues[row]
}
return ""
}
If these are your values, then you will have 3 options on 1st picker and 4 options on 2nd picker.
Adding below lines will call those functions
And your view controller class should conform to
UIPickerViewDelegate
andUIPickerViewDataSource
. LikeThis function will tell picker view how many options are to be shown
This function is responsible for placing values in picker view
Is this what you are asking for?