这是我的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
答案 0 :(得分:2)
UITabBarController
必须是窗口的rootViewController。然后,您将每个UINavigationBarController
添加为标签栏的contentView
。
答案 1 :(得分:-1)
EventsMasterViewController *firstViewController = (EventsMasterViewController *)[[navigationController viewControllers] objectAtIndex:0];
因为您将firstViewController设置为导航控制器本身。