3

I have a dynamic UIPickerView that work like that :

  • Begin with only 1 component
  • When select a row, add a new component

For precision, by component I mean column.

I want only my last added component to be actived. Others one should be completely disabled and should not even be able to scroll or be able to select rows.

I already know how to add a component dynamically but I have no idea to disable one.

Is there any way to do that ?

Yaman
  • 3,949
  • 4
  • 38
  • 60

2 Answers2

3

I'm unaware of a way to disable a component without implementing it entirely by yourself, but what you could do is display only one component at a time and add an accessory view with a "back" button, so for example, if you were selecting a location, you would show a component with states, and when the user selected a state, you would replace that component with one with city names for that state and add a "back" button for them to backtrack if necessary. That is the cleanest solution I know of for what you want to do.

If you absolutely have to "disable" a component, you will have no choice but to subclass UIPickerView and override the touchesBegan:withEvent and similar methods to basically ignore touches to other components. To "disable" you could lay a gray layer with alpha < 1.0 over the disabled component. I have to warn you this can get ugly and have unforseen and undesirable consequences if not implemented properly. Good luck.

HackyStack
  • 4,887
  • 3
  • 22
  • 28
  • I already thought about this solution but unfortunately, this is not up to me, my boss want to implement it this way :( – Yaman Jan 10 '13 at 19:38
  • I edited my answer to describe how you could "disable" a component. I can't recommend it, but it is possible. Good luck. – HackyStack Jan 11 '13 at 13:30
1

I created two UIViews, one to hold the picker and a subview with user input enabled to captures touches. place this over the component and you can toggle userInputEnabled as needed.

fadecutmike
  • 70
  • 1
  • 8