2011-04-05 57 views
3

我正在使用導航控制器。我的RootViewController推送了許多視圖,但它也提供了一個模態視圖。該模式視圖呈現一個tableView。所以我想要做的是找出我可以推動導航控制器跨模態視圖,然後使用它從該模式視圖推視圖與tableView?或禁止,有沒有辦法從模態視圖實現第二個導航控制器?Modal View中的NavigationController?

真正的問題是我想用tableView使用從右到左的過渡來呈現視圖,這當然不適用於模態視圖。

我有這樣的代碼之類的提供由導航控制器用於左過渡權:

NewViewController *newViewController = [[NewViewController alloc] init]; 
[self presentModalViewController:newViewController animated:NO]; 

CGSize theSize = CGSizeMake(320, 460); 
newViewController.view.frame = CGRectMake(0 + theSize.width, 0 + 20, theSize.width, theSize.height); 
[UIView beginAnimations:@"animationID" context:NULL]; 
[UIView setAnimationDuration:0.5]; 
newViewController.view.frame = CGRectMake(0, 0 + 20, 320, 460); 
[UIView commitAnimations]; 
[newViewController release]; 

的問題是OldViewController(在一個調用NewViewController)立即消失,所以NewViewController跨越過渡一個空白屏幕,而不是覆蓋OldViewController。

+0

你可以用'presentModal ... animated:false'來做'UIView動畫'。有沒有理由壓倒現有的動畫? – 2011-04-05 18:42:01

+1

我試圖從導航控制器中獲得從右到左的動畫過渡。 – 2011-04-05 19:18:38

+0

很難說出這裏要問什麼。這個問題含糊不清,含糊不清,... – 2011-04-06 22:58:07

回答

10

呈現UIViewController以模態方式創建一個全新的導航堆棧。你可以這樣做:

//Create the view you want to present modally 
UIViewController *modalView = [[UIViewController alloc] init]; 
//Create a new navigation stack and use it as the new RootViewController for it 
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:modalView]; 
//Present the new navigation stack modally 
[self presentModalViewController:nav animated:YES]; 
//Release 
[modalView release]; 
[nav release]; 

這可以這樣做,因爲UINavigationController是UIViewController的子類。當加載新視圖時,您可以根據需要使用它(將頂視圖上的其他視圖,UIView動畫(如Waqas建議等))。

我希望我的問題正確。請告訴我是否沒有。

+0

謝謝。我現在擁有的是:[RootViewController1] - >呈現[ModalViewController2] - >呈現[ViewController3與模態轉換]。我現在想要的是:[RootViewController1] - >呈現[ModalViewController2] - >呈現[推送ViewController3與導航控制器轉換]。這是否可以使用你所說明的方法? – 2011-04-05 19:23:55

+0

它應該做的伎倆。想想看,我相信這裏有一個簡單的解決方案 - 您可以模態地呈現第一個視圖,然後在viewDidAppear方法中將其上的表視圖推上去。 – nadavhart 2011-04-05 19:28:36

+0

另外,如果因爲中間視圖而出現延遲,您可以試着用Animated:NO模式推動它。 – nadavhart 2011-04-05 19:31:20

相關問題