自定义视图控制器未在KYArcTab中加载

时间:2013-01-20 18:51:54

标签: ios objective-c

我试图使用这个tab bar view controller但是很难让它加载我的视图控制器。

我已经按照他们的视图填充我的视图控制器,但我得到的只是黑色视图(可能是零?)。我已经设置了一个断点,self.tabBarItems充满了我的视图控制器。这意味着,如果我给它2个视图控制器,则计数为2,但我无法看到更多细节: enter image description here

查看tabBarItems如何有2个对象,但即使单击了下拉箭头,也没有列出任何内容?

无论如何,代码非常简单。

我的代码:

- (void)setup {

  // Set View Frame
    self.viewFrame = (CGRect){CGPointZero, {kKYViewWidth, kKYViewHeight}};

    // Add child view controllers to each tab
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

        _salesViewController  = [[SalesViewController alloc] initWithNibName:@"SalesViewController_iPhone" bundle:nil];

        _customersViewController = [[CustomersViewController alloc] initWithNibName:@"CustomersViewController_iPhone" bundle:nil];

        _itemsViewController = [[ItemsViewController alloc] initWithNibName:@"ItemsViewController_iPhone" bundle:nil];

        _employeesViewController = [[EmployeesViewController alloc] initWithNibName:@"EmployeesViewController_iPhone" bundle:nil];

        _settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPhone" bundle:nil];

    } else {

        _salesViewController  = [[SalesViewController alloc] initWithNibName:@"SalesViewController_iPad" bundle:nil];

        _customersViewController = [[CustomersViewController alloc] initWithNibName:@"CustomersViewController_iPad" bundle:nil];

        _itemsViewController = [[ItemsViewController alloc] initWithNibName:@"ItemsViewController_iPad" bundle:nil];

        _employeesViewController = [[EmployeesViewController alloc] initWithNibName:@"EmployeesViewController_iPad" bundle:nil];

        _settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad" bundle:nil];
    }

  // Set child views' Frame
    CGRect childViewFrame = self.viewFrame;
    [_salesViewController.view   setFrame:childViewFrame];
    [_customersViewController.view   setFrame:childViewFrame];
    [_itemsViewController.view setFrame:childViewFrame];
    [_employeesViewController.view  setFrame:childViewFrame];
    [_settingsViewController.view  setFrame:childViewFrame];

  // Add child views as tab bar items
  self.tabBarItems = @[@{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 1],
                         @"Sales" : _salesViewController} ,
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 2],
                        @"Customers" : _customersViewController}
    ];

  // Add a gesture signal on the first view
  UIImage * gestureImage = [UIImage imageNamed:kKYIArcTabGestureHelp];
  CGRect gestureImageViewFrame =
    (CGRect){{(kKYViewWidth - gestureImage.size.width) / 2.f,
              (kKYViewHeight - kKYTabBarHeight - gestureImage.size.height) / 2.f},
             gestureImage.size};
  UIImageView * gestureImageView = [[UIImageView alloc] initWithFrame:gestureImageViewFrame];
  [gestureImageView setImage:gestureImage];
  [gestureImageView setUserInteractionEnabled:YES];
  [_salesViewController.view addSubview:gestureImageView];
}

演示代码可以正常工作如果我交换它:

// Override |KYArcTabViewController|'s |-setup|
- (void)setup {
  // Set View Frame
  self.viewFrame = (CGRect){CGPointZero, {kKYViewWidth, kKYViewHeight}};

  // Add child view controllers to each tab
  viewControllerOne_   = [[UIViewController alloc] init];
  viewControllerTwo_   = [[UIViewController alloc] init];
  viewControllerThree_ = [[UIViewController alloc] init];
  viewControllerFour_  = [[UIViewController alloc] init];

  // Set child views' Frame
  CGRect childViewFrame = self.viewFrame;
  [viewControllerOne_.view   setFrame:childViewFrame];
  [viewControllerTwo_.view   setFrame:childViewFrame];
  [viewControllerThree_.view setFrame:childViewFrame];
  [viewControllerFour_.view  setFrame:childViewFrame];

  // Set child views' background color
  [viewControllerOne_.view   setBackgroundColor:[UIColor blackColor]];
  [viewControllerTwo_.view   setBackgroundColor:[UIColor redColor]];
  [viewControllerThree_.view setBackgroundColor:[UIColor greenColor]];
  [viewControllerFour_.view  setBackgroundColor:[UIColor blueColor]];

  // Add child views as tab bar items
  self.tabBarItems = @[@{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 1],
                         @"viewController" : viewControllerOne_},
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 2],
                         @"viewController" : viewControllerTwo_},
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 3],
                         @"viewController" : viewControllerThree_},
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 4],
                         @"viewController" : viewControllerFour_}];

  // Add a gesture signal on the first view
  UIImage * gestureImage = [UIImage imageNamed:kKYIArcTabGestureHelp];
  CGRect gestureImageViewFrame =
    (CGRect){{(kKYViewWidth - gestureImage.size.width) / 2.f,
              (kKYViewHeight - kKYTabBarHeight - gestureImage.size.height) / 2.f},
             gestureImage.size};
  UIImageView * gestureImageView = [[UIImageView alloc] initWithFrame:gestureImageViewFrame];
  [gestureImageView setImage:gestureImage];
  [gestureImageView setUserInteractionEnabled:YES];
  [viewControllerOne_.view addSubview:gestureImageView];
  [gestureImageView release];
}

仅供参考:演示代码中遗漏了一些东西,这些东西只是声明属性,初始化和合成等基本内容(虽然没什么特别的)。我也尝试过使用和不使用存取器(self。vs _var)

所以基本上我想知道为什么我的客户查看控制器没有加载?就像我说的,我只是得到黑屏(标签栏后面)。

1 个答案:

答案 0 :(得分:0)

所以问题在于

self.tabBarItems = @[@{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 1],
                         @"viewController" : viewControllerOne_},
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 2],
                         @"viewController" : viewControllerTwo_},
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 3],
                         @"viewController" : viewControllerThree_},
                       @{@"image"          : [NSString stringWithFormat:kKYITabBarItemImageNameFormat, 4],
                         @"viewController" : viewControllerFour_}];

需要单词“viewController”而不是视图控制器的名称。这是父类用于检索视图的键。