我想使用没有导航控制器的标签栏控制器,我希望它以编程方式发生。
我的MainViewController是TabBarController的子类,这里的代码是:
(void)viewDidLoad
{
[super viewDidLoad];
self.viewControllers = [NSArray arrayWithObjects:
[self myLikesViewControllerWithTabTitle:@"My Likes" image:[UIImage imageNamed:@"tab_feed.png"]],
[self mainStreamViewControllerWithTabTitle:@"Stream" image:nil],
[self viewControllerWithTabTitle:@"Messages" image:[UIImage imageNamed:@"tab_messages.png"]], nil];
self.tabBarController.selectedIndex = 2;
}
其中:
// Create a view controller and setup it's tab bar item with a title and image
-(UIViewController*) viewControllerWithTabTitle:(NSString*) title image:(UIImage*)image
{
UIViewController* viewController = [[UIViewController alloc] init];
viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
return viewController;
}
// Create a view controller and setup it's tab bar item with a title and image
-(UIViewController*) myLikesViewControllerWithTabTitle:(NSString*) title image:(UIImage*)image
{
UIViewController* viewController = [[UIViewController alloc] initWithNibName:@"MyLikesViewController" bundle:nil];
viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
return viewController;
}
// Create a view controller and setup it's tab bar item with a title and image
-(UIViewController*) mainStreamViewControllerWithTabTitle:(NSString*) title image:(UIImage*)image
{
UIViewController* viewController = [[UIViewController alloc] initWithNibName:@"StreamViewController" bundle:nil];
viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
return viewController;
}
我可以看到正在创建的标签,但无论我点击什么,我都看不到我创建的XIB要打开。
我错过了什么吗?
由于