【发布时间】:2014-06-20 09:42:03
【问题描述】:
我正在使用故事板来构建我的应用的 UI。本质上,我将UINavigationController 作为modal 视图打开,并且在这个导航控制器中,我将rootViewController 嵌入另一个UIViewController 的实例(位置选择视图 )。这一切都是在故事板中设置的,看起来基本上是这样的:
现在,我想访问LocationSelectionViewController 的viewDidLoad 中的导航控制器,以便在导航栏中包含UISearchBar:
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;,但这不起作用,因为我的UINavigationController 此时为零,我知道是因为我设置了一个断点并记录了它:
(lldb) po self.navigationController
nil
有谁知道为什么或我必须做什么才能在我的LocationSelectionViewController 上实际访问UINavigationController 的实例?
更新:这里有更多代码,标题实际上只包含声明
LocationSelectionViewController.h
@protocol LocationSelectionViewControllerDelegate <NSObject>
- (void)setLocation:(Location *)location;
@end
@interface LocationSelectionViewController : UIViewController <GMSGeocodingServiceDelegate, UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDataSource, UITableViewDelegate, GMSMapViewDelegate>
@end
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];
}
【问题讨论】:
-
您是否正在以编程方式初始化 LocationSelectionViewController ?
-
不,它是由故事板实例化的。它通过 root view 类型的 Relationship Segue 嵌入到
UINavigationController -
而
UINavigationController也被storyboard实例化了。在以 modal 视图打开它的视图控制器中,我查看了prepareSegue,可以看到Segue的destinationViewController实际上是UINavigatoinController。 -
Destination viewController 必须是 UINavigationController ,这样没有错。
-
是的,我知道 ;) 这让我很困惑
标签: ios objective-c uinavigationcontroller uinavigationbar uinavigationitem