Reputation: 1197
I wanted to use a UIPicker to simulate a drop-down menu and I found this code. It`s the second answer.
Its exactly what I was locking for except for one thing. When I tap my TextField activating the method, like the author sais i should do, it takes a while for the UIPicker to show up. I would like to know if theres a way to make the code faster.
I think this happens because the method creates a UIPicker every time, but I`m not sure. Sorry if it is a stupid question.
Thanks
Upvotes: 1
Views: 327
Reputation: 4388
What I have done in the past is create the UIPickerView
as a property
of my UIViewController
and then use the hidden
property to display and dismiss it. You could even animate it up and down if you wanted to rather than just hide it. This way you will not be creating it every time. I could see how the creation would take a while if you are having to set it up with a lot of data or pulling the data from somewhere else.
So if I was you, I'd create it in viewDidLoad
and then hide it until you are ready to use it instead of creating it each time. Or use an animation to take it on and off the screen.
One thing to remember, you are using the same UIPickerView
each time, so you may want to set it up to some sort of default each time before you display it so it isn't just equal to whatever value they put in last upon display.
Likewise, I would create the toolbar and save it as a property
as well and just hide or display both of them at the same time.
Upvotes: 1