简体   繁体   English

不明白如何在iPhone中使用导航控制器

[英]don't understand how to use navigation controller in iphone

I'm extremly new to iphone and I have the following misunderstanding. 我对iphone非常陌生,我有以下误解。

All over internet the tutorials about how to use NavigationController programatically it says: 在互联网上有关如何以编程方式使用NavigationController的教程,它说:

 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. 我有这个:一个UIViewController类含义( AdiViewController.h, AdiViewController.m and AdiViewController.xib) ,没有Delegate file意味着没有applicationDidFinishLaunching方法。

What I wanna do is from my class- AdiViewController when pressing a button to go to another view. 我想要做的是从我的AdiViewController按下按钮转到另一个视图。 I understand that I need a NavigationController which should retain my views having the root AdiViewController . 我知道我需要一个NavigationController ,它应该保留我的视图,拥有根AdiViewController

But my problem is where should I initializate that NavigationController in viewDidAppear ??...cause I don't have the Delegate files. 但我的问题是我应该在viewDidAppear初始化那个NavigationController ?...因为我没有Delegate文件。

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. 必须在applicationDidFinishLaunching中声明NavigationController - >这不是真的。 In your AdiViewController if you have button when you push that button you want to load navigation Controller right ? 在您的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];
}

If you are in AnotherViewController ie, you are in root view controller of Navigation controller. 如果你在AnotherViewController中,即你在导航控制器的根视图控制器中。 You need to push and pop view controllers from there. 您需要从那里推送和弹出视图控制器。 For example if you have a button in 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];
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM