jimijon
jimijon

Reputation:

How do I make a reusable XIB with it's own UIViewController?

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?

Upvotes: 1

Views: 573

Answers (2)

U62
U62

Reputation: 4363

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];

Upvotes: 2

Adam Preble
Adam Preble

Reputation: 2222

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?

Upvotes: 2

Related Questions