Search code examples
iosswiftuipickerview

Pop up UIPickerView on button click (Swift)


How do I pop up a UIPickerView (which is not on the screen) with a button click? I can't find any sources online which do this.


Solution

  • Follow these steps...

    1. create a UIView in a view controller in the main.storyboard file and add a UIPicker view inside it.

    2. connect the view and the picker view to the viewController.swift with a IBOutlet

    3. in the ViewDidLoad method, hide the the uiview we created.

    4. when the button is clicked, unhide the uiview you created, and get the user input.

    Here is an example...

    enter image description here