I'm going to cut right to the chase: my application has grown quite a bit, and now I think it's time for me to do some tidying up. I want to separate some of my views from my MainMenu.xib file into their own Nib file. The part that's tripping me up is the whole "Interface Builder + My Code" thing. Here's what I've done so far:
I've added a view controller proxy object:
In the Identity inspector, I've added my view controller's class name to the Custom Class field.
In the Attributes inspector, I've entered the name of the Nib I want to load up.
I've connected the view controller object's view outlet to an existing view in MainMenu.xib.
Finally, I hit Cmd+R, and my view isn't there.
[Insert image of FFFFUUUUU meme here.]
What am I missing? I've been staring at my Mac day-in and day-out for the last two weeks, so I wouldn't be surprised if I've completely left something out. If anyone sees my n00b ways and would be willing to point me in the right direction, I'd be really grateful. Thanks.
You almost got it.
I published a demo-project on Github, just for you ;)
Finally, you need to actually add the view to the window. Do this in your AppDelegate
,
or wherever you think is suitable.
- (void)awakeFromNib {
[self.window.contentView addSubview:self.customViewController.view];
[self.customViewController.view setFrame:[self.window.contentView bounds]];
}
Or course, you first need to make an outlet for your view controller:
@property (assign) IBOutlet ITCustomViewController *customViewController;
来源:https://stackoverflow.com/questions/19583085/how-exactly-does-an-nsview-an-nsviewcontroller-and-mainmenu-xib-fit-together