Search code examples
objective-ciosuitextfielduipickerview

Suppress UIPickerView from loading - Obj C


I have a UIPickerView that I created programmatically. It shows up when someone presses the UITextField on the screen. The only problem is that if someone presses the UITextField after the UIPickerView has already been populated, more and more PickerViews start layering on top of the previous one.

What is the proper way to suppress populating a UIPickerView if one is already on screen?


Solution

  • There are ofc. multiple ways of doing this, but the most simple would be to just keep a reference to UIPickerView. In other words just store it away in a class variable and check if it's not nil.

    You could also set the tag property on the UIPickerView and by querying it's super view check if it is already there. More info on tags: http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instp/UIView/tag

    Does that make sense?