开发者

don't understand how to use navigation controller in iphone

I'm extremly new to iphone and I have the following misunderstanding.

All over internet the tutorials about how to use NavigationController programatically it says:

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

I have this: A UIViewController class meaning(AdiViewController.h, AdiViewController.m and AdiViewController.xib) and no Delegate file meaning no applicationDidFinishLaunching method.

What I wanna do is from my class-AdiViewController when pressing a button to go to another view. I understand that I need a NavigationController which shoul开发者_运维问答d retain my views having the root AdiViewController.

But my problem is where should I initializate that NavigationController in viewDidAppear??...cause I don't have the Delegate files.

If you could provide a minimal example with this small issue of mine it would be great.I'm sure that for those how are senior this is nothing but still I don't get it.Thanks


NavigationController must be declared in applicationDidFinishLaunching -> this is not true. In your AdiViewController if you have button when you push that button you want to load navigation Controller right ?

// 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];
}

If you are in AnotherViewController i.e., you are in root view controller of Navigation controller. You need to push and pop view controllers from there. For example if you have a button in 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜