This question already has an answer here:
I have a UIPickerView which has lets say 4 Elements in it, now if one element is selected, I want that one Element to not be selectable anymore. I have managed to gray out the already selected ones, however they are still selectable. How can I make these rows not clickable or disable them?
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView.tag == 300 {
if selectedCourseLeads.contains(courseLeads[row]) {
pickerView.selectRow(row + 1, inComponent: 0, animated: true)
}
return courseLeads[row].firstName + " " + courseLeads[row].name
}
else {
return courseHelpers[row].firstName + " " + courseHelpers[row].name
}
}
Here the already selected elements are grayed out under the if statement which compares both arrays.