UINavigationController:最简单的例子 [英] UINavigationController: Simplest Example

查看:103
本文介绍了UINavigationController:最简单的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个非常简单的UINavigationController示例。这是我的代码:

I'm trying to do very simple example of a UINavigationController. Here is my code:

- (void)viewDidLoad {
  [super viewDidLoad];

下一行有效,或至少不会爆炸。

This next line works, or at least doesn't blow up.

  navController = [[UINavigationController alloc] initWithRootViewController:self];
  self.title = @"blah";

  PageOneController *one = [[[PageOneController alloc]init] autorelease];

示例1.此行没有

  [navController pushViewController:one animated:NO];

示例2.此行工作(但当然没有导航控制器)

Example 2. THIS LINE WORKS (but no nav controller, of course)

  [self.view addSubview:one.view];
}

为什么我无法将ViewController实例推送到navController并查看屏幕更改?

注意:我意识到我的概念可能会倒退而且我不需要我的查看引用 UINavigationController ...或其他东西。

Note: I realize that I might have my concepts backwards and I don't need to have my view referencing a UINavigationController... or something.

推荐答案

- (void)viewDidLoad {
    [super viewDidLoad];

    PageOneController *one = [[[PageOneController alloc]init] autorelease];
    one.title = @"blah";
    navController = [[UINavigationController alloc] initWithRootViewController:one];
    [self.view addSubview:navController.view];
}

它背后的基本思想是导航控制器的根视图控制器是控制器哪个视图将首先显示在导航控制器层次结构中。根控制器不是您将导航控制器插入的视图控制器。希望这会有所帮助。

The basic idea behind it is that a navigation controller's root view controller is the controller which view will be displayed first in the navigation controller hierarchy. The root controller is not the view controller that you plug the navigation controller into. Hope this helps.

这篇关于UINavigationController:最简单的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆