Disable UIPickerView Column

How to disable a UIPickerView column?

I want to disable only one collector column. Suppose I have a collector with 3 columns, and I want to disable the second column.

+4
source share
2 answers

There are a couple of options here.

1) Grab the interaction with the second column and redefine it.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; 

This method can be implemented to simply return to where it was before the choice. However, they can still interact with the second column.

2) Just remove the column from the collector.

I think this is the best option. Have a few boolean "showSecondColumn". Then in:

 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 

you can just check your little flag and return the corresponding number. UIPickerView has a method: reloadAllComponents

Good luck

+1
source

There seems to be no way to disable a column. I solved (not the best solution) as follows:

  • get the column as an “image” (snapshot)
  • Grayscale image
  • enable image interaction.
  • add image view to subview as subview

If there is a better way, it will be great.

0
source

Source: https://habr.com/ru/post/1336441/


All Articles