开发者

Why "add subview" not work?

开发者 https://www.devze.com 2022-12-20 12:09 出处:网络
I try add subview but not work. My code is: HomeViewController* homeViewController = [[HomeViewController alloc] initWithNibName:@\"HomeView\" bundle:nil];

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 ru开发者_运维技巧n my app HomeView appears but I can't use it as subview.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号