node ninja
node ninja

Reputation: 33026

Why does self.navigationController become nil?

I have this code:

ViewController2 *childView = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
[self.navigationController pushViewController:childView animated:YES];

I the first line, self.navigationController has a value.

On the second line, its value becomes 0. Why is that?

Upvotes: 1

Views: 2637

Answers (1)

imaginaryboy
imaginaryboy

Reputation: 5999

Unless you have overridden initWithNibName:bundle: in ViewController2 to do something truly unfortunate, there's extremely little chance that what you're saying can be true.

If you alter your code with this following assertion, does the assertion really trigger?

UINavigationController* navigationController = self.navigationController;
ViewController2 *childView = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
NSAssert(navigationController == self.navigationController, @"I was removed from the navigation controller!");
[self.navigationController pushViewController:childView animated:YES];

Upvotes: 2

Related Questions