Search code examples
iphoneobjective-cuipicker

UIPicker specific question(iphone)


I am starting to learn to use the UIPicker in an application. what I want to do is that when the user clicks on the zipcode textbox, I want the uipicker to pop up and display list of zipcodes available. Just like a drop down in c# or VB.net. Do I have to create a new view and place the uipicker there? Thanks


Solution

  • In order to have a UIPickerView appearing in your app you do not need an additional view.

    Assuming you are in a UIViewController:

    @interface MyController : UIViewController {
        UIPickerView* mPicker;
    }
    -(void)showPicker;
    -(void)hidePicker;
    @end
    
    -(void)showPicker {
        [self.view addSubview:mPicker];
        mPicker.center = CGPoint // set out of sight
    
        [UIView beginAnimations:nil context:nil];
        // do your transformations
        [UIView commitAnimations];
    }
    
    -(void)hidePicker {
        // do your exit animations
    }
    

    You can also add a delegate function to the second animations to remove the mPicker from the superview.

    For more information have a look at the UIView Reference.