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

Categories

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

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

1 Answer

- (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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...