查看未显示“有时”可可

时间:2011-06-30 12:37:35

标签: objective-c cocoa macos

在我的AppDelegate-> applicationWillFinishLaunching中我加载了两个视图控制器

NSViewController *v = [[MyCustomViewController alloc] initWithNibName:@"aNib" bundle:nil];

MyCustomViewController的initWithNibName:bundle:方法是自动生成的:

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
...

我在自定义视图中添加他们的视图: [theMainView addSubview:[v view]]

我无法理解为什么有时候(比如十次中的一次)加载了视图但没有显示。

编辑:

MyCustomViewController1 *v = [[MyCustomViewController1 alloc] initWithNibName:@"aNib" bundle:nil];
[themainview addSubview:[v view]];

MyCustomViewController2 *v2 = [[MyCustomViewController2 alloc] initWithNibName:@"aNib2" bundle:nil];
[themainview addSubview:[v2 view]];

self.view1 = [[themainview subviews] objectAtIndex:0];
self.view2  = [[themainview subviews] objectAtIndex:1];

[view2 setHidden:YES];

view1和view2是在AppDelegate中合成的2个NSView属性

1 个答案:

答案 0 :(得分:0)

您的问题可能是您依赖于视图位于主视图subviews数组的特定索引处。你需要确定你正在设置正确的观点。

请改为尝试:

MyCustomViewController1 *v = [[MyCustomViewController1 alloc] initWithNibName:@"aNib" bundle:nil];
[themainview addSubview:[v view]];

MyCustomViewController2 *v2 = [[MyCustomViewController2 alloc] initWithNibName:@"aNib2" bundle:nil];
[themainview addSubview:[v2 view]];

self.view1 = [v view];
self.view2  = [v2 view];

[view2 setHidden:YES];