The idea basically is:
Inside of myViewController NIB I have a UIView as a subview, with connections to an IBOutlet on MyViewController class. I want to load the UIView subview from a NIB also. The subView also has a class associated with it. But the subview is not showing. Here is what I do
on MyViewController.h
@interface MyViewController : UIViewController {
IBOutlet SubView *subView; // this outlet is connected to an empty UIView on IB
}
@end
on MyViewController.m
-(id)init {
if ((self = [super init])) {
// load the main view
[[NSBundle mainBundle] loadNibNamed:@"myViewController" owner:self options:nil];
// load the sub view from another NIB
self.subView = [[[NSBundle mainBundle] loadNibNamed:@"subView" owner:self options:nil] objectAtIndex:0];
}
}
the SubView.h is defined as:
@interface SubView : UIView {
}
@end
What am I doing wrong?
GianPac – shameless self-promotion, but I did a blog post about this about a month ago. Feel free to ignore the drop-shadow related code.
http://nathanhjones.com/2011/02/20/creating-reusable-uiviews-with-a-drop-shadow-tutorial/
Also, I (thanks to advice from several people) avoid ever having more than one view controller on my ‘view’. The method I outline above allows you to accomplish this and still use IB to do the layout/outlets.