我一直在试验Apple的SimpleDrillDown示例,并尝试将其放入标签栏。问题是现在没有显示的视图,我知道App Delegate中的以下代码是导致它的。我正在努力改变它以适应tabbar并且会欣赏一些指示。
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Create the data controller and pass it to the root view controller.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
RootViewController *rootViewController = (RootViewController *)[[navigationController viewControllers]objectAtIndex:0];
DataController *controller = [[DataController alloc] init];
rootViewController.dataController = controller;
self.dataController = controller;
}
我已将其替换为以下内容,但此行EatCatTVC *rootViewController = (RootViewController *)[[navigationController viewControllers]objectAtIndex:0];
会引发错误
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
// Create the data controller and pass it to the root view controller.
EatCatTVC *rootViewController = (RootViewController *)[[navigationController viewControllers]objectAtIndex:0];
DataController *controller = [[DataController alloc] init];
rootViewController.dataController = controller;
self.dataController = controller;
return YES;
}
答案 0 :(得分:1)
您的代码失败,因为您正在访问不存在的对象
EatCatTVC *rootViewController = (RootViewController *)[[navigationController viewControllers]objectAtIndex:0];
1在您的“已修改”版本中不存在navigationController
。
确保“rootController”设置为UITabBarController
类(我假设你在Interface Builder中设置了它)。
然后使用setViewControllers:animated:
提供要存在的UITabBarController' instance with (for instance)
UIViewController实例。