I am using storyboards to build my app's UI. Essentially, I am opening a UINavigationController
as modal view, and in this navigation controller, I embed as rootViewController
an instance of another UIViewController
(Location Selection View). This is all set up in storyboard and looks basically like this:
Now, I want to access the navigation controller in the viewDidLoad
of LocationSelectionViewController
in order to include a UISearchBar
in the navigation bar with:
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
, this doesn't work however, because my UINavigationController
is nil at this point, I know because I set a breakpoint and logged it:
(lldb) po self.navigationController
nil
Does anyone know why or what I have to do so that there is actually an instance of UINavigationController
accessible on my LocationSelectionViewController
?
UPDATE: Here is more code, the header really only consists of the declarations
LocationSelectionViewController.h
@protocol LocationSelectionViewControllerDelegate <NSObject>
- (void)setLocation:(Location *)location;
@end
@interface LocationSelectionViewController : UIViewController <GMSGeocodingServiceDelegate, UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDataSource, UITableViewDelegate, GMSMapViewDelegate>
@end
Parts of LocationSelectionViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchBar.text = DUMMY_ADDRESS;
self.previouslySearchedLocations = [[CoreDataManager coreDataManagerSharedInstance] previouslySearchedLocations];
self.searchResults = [[NSMutableArray alloc] initWithArray:self.previouslySearchedLocations];
self.mapView.delegate = self;
self.gmsGeocodingService = [[GMSGeocodingService alloc] initWithDelegate:self];
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self addMapView];
}
OK, I just solved my problem. I strongly believe it was a bug in interface builder. I deleted the old navigation controller and just dragged and dropped a new one onto the storyboard, now calling po self.navigationController
in viewDidLoad
actually returns an instance of UINavigationController
. Thanks for all the help though, I appreciate it a lot!