views:

241

answers:

3

I am trying to create a reusable "picker". It is basically like a keypad of a phone. Since I will be using this a lot in my iPhone app, I have been frustrated with trying to make it appear.

It is in its own XIB file and has its own UIViewController subclass as the FileOwner. However, when I instantiate this with:

MonthPickerViewController *mpvc
    = [[MonthPickerViewController alloc] initWithNibName:@"MonthPicker"
                                                  bundle:nil];

Nothing happens on the screen. Yet is does fire the -viewWillAppear methods, etc.

So, what am I doing wrong either in code or in InterfaceBuilder that is preventing my view to appear?

+2  A: 

Are you pushing the view controller?

[[self navigationController] pushViewController:mpvc animated:YES];

Or are you adding the view controller's view as a subView of your current view?

Adam Preble
+2  A: 

First, make sure you've hooked everything up right inside Interface Builder. An easy gotcha is to forget to connect the View object up to the view outlet of your UIViewController subclass.

Then, as Adam says, you need to actually display the view. Assuming you're doing this inside the code of another view controller, you'd need something like the following if you just wanted the new view to appear ontop of your current view:

[self.view addSubview:mpvc.view];

Of if you are using a navigation controller to stack views:-

[[self navigationController] pushViewController:mpvc animated:YES];
U62
A: 

Thank you...

I was not adding it to the proper view after all. Works great now.