2013-05-06 59 views
0

我試圖使用Interface Builder(而不是Storyboard)第一次製作應用程序,但我被卡住了。是否可以在同一個XIB中使用ViewController更改視圖? 我喜歡這一點,當我點擊一個按鈕,視圖更改爲其他ViewController目前在同一XIB file。我必須回電嗎?如果是,哪個?在一個XIB中更改視圖

+0

這聽起來像你想要做的是什麼故事板。你爲什麼要使用xib文件?我認爲蘋果的意圖是,故事板應該在很大程度上取代xib文件作爲製作用戶界面的新方式。 – rdelmar 2013-05-06 16:34:31

+0

你說得對,實際上我通常使用故事板;但是我想在這個時候嘗試一下Interface Builder。問題是我幾乎完成我的應用程序,我無法重新啓動這個小問題。 – CrazySoftware 2013-05-06 16:39:48

+0

我不清楚你想做什麼 - xib文件包含視圖,而不是視圖控制器(視圖控制器通常是文件的所有者)。如果需要,可以在xib文件中放入多個視圖,並在您的一個控制器之間進行切換,但不切換視圖控制器。 – rdelmar 2013-05-06 16:43:43

回答

0

如果你有2個與2個的.xib文件視圖控制器,這樣

enter image description here

您可以從您的視圖控制器的按鈕按下方法呈現NextViewControler,

-(IBAction) yourButtonPressed:(id)sender;{ 
    NextViewController *nextViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil]; 
    [self presentViewController:nextViewController animated:YES completion:nil]; 
} 

編輯:

您可以像這樣呈現相同的視圖控制器。

-(IBAction) yourButtonPressed:(id)sender;{ 
    ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
    [self presentViewController:viewController animated:YES completion:nil]; 
} 
+0

不,我只有一個.xib文件和一個ViewController。 – CrazySoftware 2013-05-06 16:17:37

+0

我更新了答案,現在檢查。 – 2013-05-06 16:25:44

+0

謝謝,但我犯了一個錯誤;我有兩個窗口,而不是兩個ViewControllers。所以我在第一個窗口中使用了「AppDelegate」。按下按鈕時應將視圖從第一個窗口更改爲第二個窗口。抱歉! – CrazySoftware 2013-05-06 16:33:47