tabbarcontroller以编程方式添加ios,但不打开选项卡
我想使用一个没有导航控制器的选项卡栏控制器,并且我希望它以编程方式实现 My MainViewController是TabBarController的子类,下面是其中的代码:tabbarcontroller以编程方式添加ios,但不打开选项卡,ios,uiviewcontroller,uitabbarcontroller,Ios,Uiviewcontroller,Uitabbarcontroller,我想使用一个没有导航控制器的选项卡栏控制器,并且我希望它以编程方式实现 My MainViewController是TabBarController的子类,下面是其中的代码: (void)viewDidLoad { [super viewDidLoad]; self.viewControllers = [NSArray arrayWithObjects: [self myLikesViewControllerWithTa
(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
我错过什么了吗
谢谢在哪里使用viewControllerWithTabTitle:image:method?返回值?。您何时何地调用该方法?@rdelmar在ViewDidLoad中。ViewController已添加到self.viewControllers数组中。抱歉,我误读了您的代码。只要方法中的nib名称与您的实际名称匹配,您所拥有的就可以工作。您的图像可能有问题。它们的大小是否适合选项卡栏中的图像(它们的大小不适合您)?运行应用程序时,您看到了什么?