1

Here's the situation, I'm a newb at this - so I could be totally on the wrong path.

I am building an app with multiple views; in one of those views I need the user to select from a dropdown list (UIPickerView) --> for simplicity let's call that view "PC" which has PC.h and PC.m files.

Through IB I was able to drop a UIPickerView object to the PC view, and I initialize that "object" in my ViewController.h and ViewController.m files. Meaning, I'm able to load the view, populate data in the view, etc. etc.

My challenge/problem is - I want the UIPicker to be hidden until the user clicks a button on the PC view, then I want to show the UIPicker and hide it again once the user selects something from the menu.

I've searched and searched and can't find anything, so any help here is appreciated!

timw07
  • 339
  • 2
  • 5
  • 18

1 Answers1

1

assuming that your UIPickerView instance (object) is called pv;

This is how your header-file may look like:

@interface YourViewController : UIViewController 
{
    IBOutlet UIPickerView *pv;
}

@property (nonatomic, retain) UIPickerView *pv;

@end

You then need to connect the pv-instance within the InterfaceBuilder to your Picker-View.

Trivial Approach:

somewhere in your viewDidLoad of the embedding view-controller:

pv.hidden = YES;

within the button action method (connected to your button-touch-up-instide event):

pv.hidden = NO;

within the action method of your "menu"

pv.hidden = YES;
Till
  • 27,559
  • 13
  • 88
  • 122
  • thanks for the response. This makes total sense, and I've bene trying to achieve this; however, I think my problem may be how I'm passing the pv pointer. Right now this doesn't compile because of an undeclared error. If I initialized *pv in my ViewController; how can I pass that pointer to the PC Class appropriately? – timw07 Mar 26 '11 at 16:01
  • You can add it as a subview of your PC Class' view or you can create a property in your PC class for a picker view and pass it along by assigning pc.pv = self.pv in your View Controller. – Jamie Mar 26 '11 at 16:09
  • So in your View Controller you create a PC class instance. You can then call [pc.view add subView pv]; Or in your PC Class (lets call it pc) you can create a @property (retain) UIPickerView *pv; then back in your View Controller you can assign it to the PC's pv. So pc.pv = self.pv; so you're assigning the picker view of yourself to the PC classes pv. Hope that's more clear. – Jamie Mar 26 '11 at 16:25
  • thanks again for the help - now I'm getting the following error once I try to declare [pc.view addSubView pv]: Request for member 'view' in something not a structure or union. – timw07 Mar 26 '11 at 16:36
  • It seems that the whole concept of ObjectiveC is rather new for you - no worries, you will get it done. Still, I would recommend you to work through some of the tutorials Apple has provided within the documentation. Those are really well written and will get you up to speed pretty quickly. – Till Mar 26 '11 at 16:45
  • Thanks Till and Jamie, the problem was with IB - I only had the UIPicker connected to the ViewController, and not the PC view as well - looks like I'm back on track. Thanks again! – timw07 Mar 26 '11 at 16:51