这是我的 AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
EventsMasterViewController *firstViewController = (EventsMasterViewController *)[[navigationController viewControllers] objectAtIndex:0];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
EventDataController *_myEventsDataController = [[EventDataController alloc] init];
firstViewController.myEventsDataController = _myEventsDataController;
EventDataController *_upcomingEventsDataController = [[EventDataController alloc] init];
firstViewController.upcomingEventsDataController = _upcomingEventsDataController;
EventDataController *_bookmarkedEventsDataController = [[EventDataController alloc] init];
firstViewController.bookmarkedEventsDataController = _bookmarkedEventsDataController;
return YES;
}
当我唯一的视图是嵌入在导航控制器中的 MasterViewController 和 DetailViewController 时,这曾经很有效。
现在我想添加一个 TabBarController。所以我将 NavigationController 嵌入到 TabBarController 中。但是我的代表抛出了一个错误。
如图所示,我真的需要初始化我的 EventDataController 的 3 个实例。
所以我想问题是,“我如何以编程方式从 tabBarController 中获取 navigationController,以便我可以将 EventsDataControllers 添加到 firstViewController?”
更新
这是我的错误。我不明白 setMyEventsDataController 如何成为 UINavigationController 上的方法。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setMyEventsDataController:]: unrecognized selector sent to instance