Reputation: 4792
I've run into a problem with my Project.
Every time I try to access my UINavigationController from a Pushed UIViewController, I get "(null)" as a return.
So this is my project is structured:
1. AppDelegate.m initalises UINavigation Controller
2. UINavigation Controller starts with Welcome Page
3. Welcome Page Pushes New UIViewController on Button Press
4. UIViewController returns (null) when self.navigationController called
OK, so here's some code, in my Welcome Page I'm calling this:
MyClass *theChatRoom = [[MyClass alloc] initWithNibName:@"ChatRoom" bundle:nil];
[theChatRoom setTitle:[unitCode text]];
[self.navigationController pushViewController:theChatRoom animated:YES];
Which works fine, it pushes the new View Controller.
But then in MyClass.m :
@implementation MyClass
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
NSLog([NSString stringWithFormat:@"%@",self.navigationController]);
}
return self;
}
This returns (null)
What am I doing wrong?
Upvotes: 2
Views: 2462
Reputation: 4248
According the documentation, the navigationController
of UIViewController
:
This property is nil if the view controller is not embedded inside a navigation controller.
That's said, if you access the navigationController
before embedding into the UINavigationController
(not push yet), it will return nil. So you can access it in the viewDidLoad
but no in - (id)initWithNibName:bundle:
.
Upvotes: 2