2011-09-08 55 views
0

我对iPhone非常陌生,我有以下误解。不明白如何在iphone中使用导航控制器

遍布互联网有关如何使用NavigationController教程编程,它说:

NavigationController must be declared in applicationDidFinishLaunching and must be init with a root.After that you can add views to it. 

我有这样的: 一个UIViewController类的意思(AdiViewController.h, AdiViewController.m and AdiViewController.xib)没有Delegate file含义没有applicationDidFinishLaunching方法

我想要做的是从我的课AdiViewController当按下一个按钮转到另一个视图 据我所知,我需要一个NavigationController应保留我的意见h在根AdiViewController

但我的问题是我应该在哪里初始化NavigationControllerviewDidAppear ??因为我没有Delegate文件。

如果你能提供我的这个小问题一个小例子,这将是great.I'm肯定,对于那些怎么都大四了不过我仍然没有得到it.Thanks

回答

2

NavigationController必须在applicationDidFinishLaunching中声明 - >这是不正确的。 在你的AdiViewController中,如果你有按钮的时候你按下那个按钮,你想加载导航控制器的权利?

// Hook this IBAction to your button in AdiViewController 
- (IBAction)pushNavController 
{ 
    AnotherViewController* rootView = [[AnotherViewController alloc] initWithNibName:@"Anotherview" bundle:nil]; 
    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:rootView]; 
    [rootView release]; 
    [self presentModalViewController:navController animated:YES]; 
    [navController release]; 
} 

如果你在AnotherViewController即,你是在导航控制器的根视图控制器。您需要从此处推送并弹出视图控制器。例如,如果您在AnotherViewController中有一个按钮:

// push next view controller onto navigation controller's stack 
    - (IBAction)pushNextViewController 
    { 
     NextViewController* nextView = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil]; 
     [self.navigationController pushViewController:nextView animated:YES]; 
     [nextView release]; 
    } 

// Similarly if you want to go back to AnotherViewController from NextViewController you just pop that from navigation controller's stack 
- (IBAction)pushNextViewController 
    { 
     [self.navigationController popViewControllerAnimated:YES]; 
    } 
+0

是的......我想要那么多! – adrian

+0

工作你是伟大的。但是,如果当我到达我的AnotherViewController想进一步到另一个视图...我该如何继续?请你更新你的代码。谢谢 – adrian

+0

@george更新我的代码。 – 0x8badf00d

相关问题