2011-06-30 31 views
0

以我AppDelegate-> applicationWillFinishLaunching我裝載兩個視圖控制器與查看不顯示 「有時」 可可

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

MyCustomViewController的initWithNibName:束:方法是自動生成的:

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]; 

廠景和視圖2是在AppDelegate中

+0

請問您的應用程序中使用垃圾回收?如果是這樣,你是否保持強烈的視圖控制器引用? – 2011-07-01 00:30:46

回答

0

您的問題合成可能是2種的NSView性質的依賴是在themainview的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]; 
+0

我更正了* v – a438

+0

@ a438的聲明新答案。 – thomashw

+0

感謝您的幫助。但問題仍然存在 – a438