- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
HeadViewController *headViewController = [[HeadViewController alloc] initWithNibName:@"HeadViewController" bundle:nil];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
[view addSubview:headViewController.vew];
[self.view addSubview:view];
}
HeadViewController.h:
@interface HeadViewController : UIViewController
{
IBOutlet UIView *view;
}
@property (nonatomic, retain)IBOutlet UIView *view;
@end
and I connect the view to the file’s owner.
And I can’t see the headViewController.view.
First of all, you do not need to define the
viewoutlet in theHeadViewControllerclass. It is automatically inherited from theUIViewControllersuper class.Then, I suggest you to add directly the view of
HeadViewControllerto your current view. Eg.But, if you are using ARC (Automatic Reference Counting), the
headViewControllerinstance will probably be deallocated after the end of theviewDidLoadmethod. It is convenient (and I’d say it is compulsory) to assign that instance to a local variable in the controller you are currently displaying. This way you will be able to handle its view’s components later if needed, the instance will be retained, and everything else will work perfectly. You should have something like:and
in the hidden interface definition at the beginning of the
.mclass implementation file.