Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I disable selection in specific UIPickerView item?

I can find a post that teach to use delegate method to check if the row valid and then scroll to the right one if not.

But that's not I want. Can I disable the specific row after the pickerView initialized? Like "Gray-out" the row and can't stop indicator on it.

Thank you, experts.

like image 926
mineschan Avatar asked Sep 28 '11 02:09

mineschan


1 Answers

There are two parts to doing this.

  1. Use -[<UIPickerViewDelegate> pickerView:viewForRow:forComponent:reusingView:] to return a custom view for each row, such as a UILabel. For the row you want to show up as disabled, you'll need to configure the view to reflect that disabledness.
  2. In -[<UIPickerViewDelegate> pickerView:didSelectRow:inComponent:], you'll need to detect when the disabled is selected, and then use -[UIPickerView selectRow:inComponent:animated:] to "rollback" to a "valid" row.
like image 137
Dave DeLong Avatar answered Sep 30 '22 13:09

Dave DeLong