【问题标题】:push uiviewcontroller from presentModalViewController从 presentModalViewController 推送 uiviewcontroller
【发布时间】:2011-07-21 08:13:00
【问题描述】:

我使用presentModalViewController 显示视图。从这个UIView 我想使用UINavigationController 推送UIView。 我为此尝试了以下代码

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

但这对我不起作用。所以请任何人建议我如何从ModelViewController 推送视图。

谢谢

【问题讨论】:

    标签: ios objective-c iphone uinavigationcontroller presentmodalviewcontroller


    【解决方案1】:

    首先,您必须在导航控制器中展示您的模态视图控制器:

    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],但它不适用于我。所以你能建议我如何让它透明吗?谢谢
    【解决方案2】:
    -(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];
                             }
                         }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2011-04-13
      相关资源
      最近更新 更多