我试图使用这个标签栏视图控制器,但很难让它加载我的视图控制器。
我已经按照他们的演示为他们的视图控制器填充了我的视图控制器,但我得到的只是黑色视图(可能为零?)。我已经设置了一个断点,并且 self.tabBarItems 充满了我能说的最好的视图控制器。这意味着如果我给它 2 个视图控制器,则计数为 2,但我无法查看更多详细信息:
看看 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)
所以基本上我想知道为什么我的客户视图控制器没有加载?就像我说的那样,我只是得到黑屏(在标签栏后面)。