从presentModalViewController推出UIViewController

4

我使用presentModalViewController显示一个视图,并且从这个UIView中,我想使用UINavigationController推送一个UIView。 我尝试了下面的代码:

[self.parentViewController.navigationController 
                pushViewController:objViewFullScreen 
                          animated:YES];

但是这对我没有用。所以请问有人能建议我如何从 ModelViewController 推送视图。
谢谢。
2个回答

8

首先你需要在一个导航控制器中展示你的模态视图控制器:

MyViewController *vc = [[MyViewController alloc] initWithNibName:@"MyNib" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];

[self presentModalViewController:nc animated:YES];

[vc release];
[nc release];

然后在MyViewController内部,您可以执行以下操作:

OtherViewController *vc = [[OtherViewController alloc] initWithNibName:@"MyOtherNib" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
[vc release];

谢谢您的快速回复。对我有用。但是VC视图不透明。我也设置了[uicolor clearcolor],但它对我没有用。所以您能建议我如何使其透明吗?谢谢。 - Mitesh Khatri
https://dev59.com/XnRA5IYBdhLWcg3wuAcp#859215 - ySgPjx

0
-(void)pushViewControllerWithCustomAnimation:(UIViewController *)newViewController {
    newViewController.view.alpha = 0.0f;
    [self.view addSubview:newViewController.view];

    [UIView animateWithDuration:1
                     animations:^{
                         newViewController.view.alpha = 1;
                     }
                     completion:^(BOOL fin){
                         if (fin) {
                             // finally display the new viewcontroller for real
                             [self.navigationController pushViewController:newViewController animated:NO];
                         }
                     }];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接