0

I try add subview but not work. My code is:

HomeViewController* homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeView" bundle:nil];
NSViewController *viewController = homeViewController;
[mainView addSubview: [viewController view]];
NSLog(@"%@",[viewController view]);
NSLog(@"%@",[[viewController view]superview]);
NSLog(@"%@",[mainView subviews]);

The NSLog write in console:

HTPC[1467:a0f] <HomeView: 0x10042e9f0>
HTPC[1467:a0f] (null)
HTPC[1467:a0f] (null)

Why addsubview don't work? When I run my app HomeView appears but I can't use it as subview.

soulless
  • 51
  • 4

1 Answers1

3

Looks to me like mainView is nil at the time this code is executed.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • I'd agree; chances are he's doing this from an init method instead of from a viewDidLoad or awakeFromNib, etc. – geowar Jun 05 '10 at 16:23