Modal View的NavigationController?

时间:2011-04-05 18:34:54

标签: iphone xcode uinavigationcontroller

我正在使用导航控制器。我的RootViewController推送了许多视图,但它也提供了一个模态视图。该模态视图提供了一个tableView。所以我想要做的就是弄清楚我可以将导航控制器推到模态视图中,然后在该模态视图中使用它来推送带有tableView的视图?或者除此之外,有没有办法从模态视图实现第二个导航控制器?

真正的问题是我想使用从右到左过渡的tableView来呈现视图,这当然不适用于模态视图。

我有这个代码,SORT OF提供导航控制器使用的左转换权利:

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。

1 个答案:

答案 0 :(得分: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暗示等等)。

我希望我能正确地回答你的问题。如果我没有,请说明。