Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

objective c - UINavigationController: Simplest Example

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

Example 1. THIS LINE DOES NOTHING

  [navController pushViewController:one animated:NO];

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

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

Why am I unable to push ViewController instances onto the navController and see the screen change?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
- (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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...