Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable UIPickerView (Swift)?

I would like to disable the UIPickerView, but setting it to "isEnabled = false" does not work. And no, I don't want to disable the view while using it, but instead not being able to scroll through the view until a certain action is done for it to be re-enabled.

The code I tried here doesn't work (it may not even be swift code): How to disable UIPickerView (Objective-C)?

like image 690
Michael Avatar asked Dec 03 '22 23:12

Michael


1 Answers

To disable user input, use:

myPickerView.isUserInteractionEnabled = false

Then, to re-enable user input, use:

myPickerView.isUserInteractionEnabled = true

From the Apple Documentation Page on .isUserInteractionEnabled:

When set to false, user events—such as touch and keyboard—intended for the view are ignored and removed from the event queue. When set to true, events are delivered to the view normally.

like image 79
LordColus Avatar answered Dec 22 '22 07:12

LordColus