代码之家  ›  专栏  ›  技术社区  ›  Veeru

在没有导航控制器的情况下导航到另一个视图控制器

  •  3
  • Veeru  · 技术社区  · 15 年前

    你猜我还是个新手,在iphone开发上有点头绪。

    我有一个应用程序,有两个视图控制器,每个视图控制器连接一个不同的nib文件。 我试图在视图之间手动切换;不涉及导航控件。

    如何手动将第二个视图推送到第一个视图? self.navigationController pushViewController 否则,我怎么能把第二个视图推到第一个视图的顶部并破坏第一个视图;当然,反之亦然?

    SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
    [self.navigationController pushViewController:sv animated:YES];
    

    很明显,它不起作用。

    window addSubView 也不起作用,因为第一个视图控制器是根视图控制器(不确定我说的对不对)。换言之,当我运行应用程序时,第一个视图是我用一个应该加载第二个视图的按钮看到的。

    我花了好几个小时寻找一个简单的例子,但没有找到。

    有什么建议吗?

    3 回复  |  直到 13 年前
        1
  •  10
  •   Thomas Clayson    15 年前

    在第一个视图控制器中,您需要:

    - (IBAction)pushWithoutViewController:(id)selector {
        NextNavigationController *page = [[NextNavigationController alloc] initWithNibName:NextNavigationController bundle:nil];
        CGRect theFrame = page.view.frame;
        theFrame.origin = CGPointMake(self.view.frame.size.width, 0);
        page.view.frame = theFrame;
        theFrame.origin = CGPointMake(0,0);
        [UIView beginAnimations:nil context:nil]; 
        [UIView setAnimationDuration:0.8f];
        page.view.frame = theFrame;
        [UIView commitAnimations];
        [self.view addSubview:page.view];
        [page release];
    }
    

        2
  •  8
  •   Gyani    15 年前

    尝试:

    SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
    [self presentModalViewController:sv animated:YES];
    
        3
  •  0
  •   Dmitry Zhukov    13 年前

    如果您有第一个XB,并且希望将导航提供给另一个控制器,则必须声明导航到 appdelegate.m

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = navController;
    

    然后在ViewController.m中

    - (IBAction)NextButtonClicked:(id)sender
    {
        yourNextViewController *objyourNextViewController = [[yourNextViewController alloc] initWithNibName:@"yourNextViewController" bundle:nil];
        [self.navigationController pushViewController:objStartUpViewController animated:TRUE];
    }