0

我一直在尝试 Apple 的 SimpleDrillDown 示例,并尝试将其放入选项卡栏中。问题是视图现在没有显示,我知道是 App Delegate 中的以下代码导致了它。我正在努力改变它以适应标签栏,并希望得到一些指示。

- (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;
}
4

1 回答 1

1

您的代码失败,因为您正在访问不存在的对象

EatCatTVC *rootViewController = (RootViewController *)[[navigationController viewControllers]objectAtIndex:0];

navigationController在您的“修改”版本中不存在此行。

确保将“rootController”设置为UITabBarController类(我假设您确实在 Interface Builder 中进行了设置)。

然后用于setViewControllers:animated:提供UITabBarController' instance with (for instance)应该存在的 UIViewController` 实例。

于 2012-08-14T12:13:25.270 回答