0

我只是无法在我的每个标签栏项目视图中获得导航控制器(和栏)。这是我的 appdelegate ,我错过了什么?FrontPage并且Opinion也是tableviewcontrollers,只是忘记了他们名字中的表格。

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:        (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

  FrontPageViewController *frontPageVC = [[FrontPageViewController alloc] initWithNibName:nil bundle:nil];
  frontPageVC.title = @"Front Page";
  frontPageVC.tabBarItem.image = [UIImage imageNamed:@"second"];
  UINavigationController *frontPageNavController = [[UINavigationController alloc] initWithRootViewController:frontPageVC];

  CampusTableViewController *campusVC = [[CampusTableViewController alloc] initWithNibName:nil bundle:nil];
  campusVC.title = @"Campus";
  campusVC.tabBarItem.image = [UIImage imageNamed:@"second"];
  UINavigationController *campusNavController = [[UINavigationController alloc] initWithRootViewController:campusVC];

  OpinionViewController *opinionVC = [[OpinionViewController alloc] initWithNibName:nil bundle:nil];
  opinionVC.title = @"Opinion";
  opinionVC.tabBarItem.image = [UIImage imageNamed:@"second"];
  UINavigationController *opinionNavController = [[UINavigationController alloc] initWithRootViewController:opinionVC];

  SportsTableViewController *sportsVC = [[SportsTableViewController alloc] initWithNibName:nil bundle:nil];
  sportsVC.title = @"Sports";
  sportsVC.tabBarItem.image = [UIImage imageNamed:@"second"];
  UINavigationController *sportsNavController = [[UINavigationController alloc] initWithRootViewController:sportsVC];

  PDFViewController *pdfVC = [[PDFViewController alloc] initWithNibName:nil bundle:nil];

  NSArray *controllers = [NSArray arrayWithObjects:frontPageVC, campusVC, opinionVC, sportsVC, pdfVC, nil];

  self.tabBarController = [[UITabBarController alloc] init];
  self.tabBarController.viewControllers = controllers;

  self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;

  [[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];

}

谢谢你!

编辑:显然我需要输入更多来解释我的问题,因为SO不会让我在没有一定数量的单词的情况下发帖?

4

3 回答 3

2

更改此行

NSArray *controllers = [NSArray arrayWithObjects:frontPageVC, campusVC, opinionVC, sportsVC, pdfVC, nil];

到那个

UINavigationController *pdfNavController = [[UINavigationController alloc] initWithRootViewController:pdfVC];
NSArray *controllers = [NSArray arrayWithObjects:frontPageNavController, campusNavController, opinionNavController, sportsNavController, pdfNavController, nil];
于 2013-01-10T08:40:24.160 回答
0

controllers应该包括导航控制器,而不是单个控制器。

NSArray *controllers = [NSArray arrayWithObjects:frontPageNavController, campusNavController, opinionNavController, sportsNavController, pdfNavController, nil];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = controllers;

self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;

// you can remove the last line: [[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];

苹果在一个文档中说(不记得是在人机界面指南中,在视图控制器编程,标签栏控制器编程还是导航控制器编程中)如果你想拥有导航控制器和标签栏控制器,你必须把导航标签栏控制器内的控制器。

于 2013-01-10T08:38:42.240 回答
0

为什么在return语句之后给出这个方法?

[[self.tabBarController.viewControllers objectAtIndex:0] setRootViewController:frontPageNavController];

尝试在 return 语句之前给出这个或删除这个语句。因为你返回下一行不会执行。也让我们清楚地知道您的问题。你想要做什么。

于 2013-01-10T08:41:00.390 回答