2009-11-28 47 views
2

我試圖從另一個視圖控制器加載一個臨時的幻燈片視圖。我的應用程序的視圖控制器結構:使用'presentModalViewController'加載視圖

Application > Tab Bar Controller > TabBarItem > View Controller 

在這個視圖控制器,我有一個按鈕,成功觸發一個方法來加載臨時視圖:

- (IBAction)displayTimePickerViewForDayButton:(id)sender { 

    NSLog(@"displayTimePickerViewForDayButton method entered."); 

    // create the selector view controller and become the delegate 
    WOTimePickerViewController *tpvc = [[WOTimePickerViewController alloc] initWithNibName:@"WOTimePickerView" bundle:nil]; 
    tpvc.delegate = self; 
    tpvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 

    [self presentModalViewController:tpvc animated:YES]; 
    [tpvc release]; 
} 

我已經驗證了我的WOTimePickerViewController成功返回從init方法,但視圖永遠不會輸入它的viewDidLoad方法。

所以,如果我看看IB的視圖,它似乎連接到vc的「視圖」屬性。當我在模擬器(從IB)中運行視圖時,它可以正確渲染。

當我從XCODE運行應用程序時,我可以導航到視圖,單擊我的按鈕,並出現一個空白的白色屏幕(注意,這不是應加載的視圖的白色背景)。

+0

建設的問題?也許你可以嘗試刪除項目目錄中的'build'目錄,然後再使用Xcode進行編譯。所有的資源應該在那時正確地更新。 – Joost 2009-11-29 10:08:26

回答

4

你應該做這樣的..

WOTimePickerViewController *tpvc = [[WOTimePickerViewController alloc] initWithNibName:@"WOTimePickerView" bundle:nil]; 
    tpvc.delegate = self; 
UINavigationController *navCntrlr = [[UINavigationController alloc] initWithRootViewController:tpvc]; 
    navCntrlr.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 

    [self.navigationController presentModalViewController:tpvc animated:YES]; 
    [tpvc release]; 

但你缺少最重要的是你是不是做是正確的。

你應該這樣做,如:

[self.navigationController presentModalViewController:tpvc animated:YES]; 

,當你想關閉該modalView控制器,你應該這樣做,如:

[self.navigationController dismissModalViewControllerAnimated:YES]; 
+1

只要他從UIViewController派生類中調用presentModalViewController,我不明白他爲什麼需要使用導航控制器。你需要一個導航控制器來使用pushViewController。 – Oscar 2011-01-17 10:15:43

1

我認爲視圖控制器的modalTransitionStyle適用於顯示模式視圖該視圖控制器。所以如果你想使用UIModalTransitionStyleCoverVertical過渡來顯示你的模態控制器,你應該在父視圖控制器(self)上設置modalTransitionStyle屬性,而不是新的。

我沒有任何使用modalTransitionStyle的經驗,但也許在視圖加載之前設置該屬性導致一些問題?我會嘗試評論它...

這聽起來像是在IB中正確配置了一切。只要你的文件的所有者是視圖控制器,並且它的視圖出口綁定到視圖,你應該是好的。

希望幫助,

相關問題