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

发布于 2024-12-03 20:18:46 字数 829 浏览 0 评论 0原文

我对 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 和 AdiViewController.xib),并且没有 Delegate 文件 意味着没有 applicationDidFinishLaunching代码>方法。

我想要做的是当按下按钮转到另一个视图时,从我的类 AdiViewController 中进行操作。 我知道我需要一个 NavigationController ,它应该保留我的具有根 AdiViewController 的视图。

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

如果你能为我的这个小问题提供一个最小的例子,那就太好了。我确信对于那些高级的人来说这没什么,但我仍然不明白。谢谢

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 should 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2024-12-10 20:18:46

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

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];
    } 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文