2011-04-15 22 views
1

我正在創建一個應用程序,在該應用程序中,我可以使用名爲「1」和「2」的頂部按鈕交換視圖....使用它們可以交換盒子中的視圖。我正在使用視圖控制器。但問題是我想使用視圖內的按鈕來交換我的視圖。我想在一個視圖內按下按鈕時切換視圖。我試過所有的東西,但沒有工作。 [box setContentView:v]; [box addSubview:v]; 請幫忙 enter image description here在Mac應用程序中交換視圖

+0

,請複製粘貼不工作的源代碼。 – 2011-04-18 06:18:27

+0

你有沒有得到這個工作,因爲我有同樣的問題? – Cragly 2011-07-15 16:46:02

+0

是的,我能解決使用視圖控制器或使用BOx – 2011-07-16 12:35:03

回答

1

看看[NSView replaceSubview:with:];

+0

是的我已經嘗試過,但它不工作。這兩個視圖是兩個不同的類。當點擊但不工作時,我將視圖編號發送到主類。 – 2011-04-15 07:21:17

0

對於鍵 '1' 行動......

 
//For opening the second nib on first button click 
NSWindowController * second=[[NSWindowController alloc] initWithWindowNibName:@"secondNIB"]; 
[second showWindow:self]; 

//For closing the first nib, optional 
//firstWindow is NSWindow 
[firstWindow orderOut:nil]; 

對於按鍵 '2' 的動作...

 
//For opening the first nib on second button click 
NSWindowController * first=[[NSWindowController alloc] initWithWindowNibName:@"firstNIB"]; 
[first showWindow:self]; 

//For closing the second nib, optional 
//secondWindow is NSWindow 
[secondWindow orderOut:nil]; 
+0

您的回答描述了OP在詢問視圖交換時如何顯示和關閉窗口。 – 2011-04-18 05:57:29

+0

是的,我想改變視圖,即NSView交換。我沒有使用窗口控制器。 – 2011-04-19 04:59:48

相關問題