UITabBarItems不会出现

时间:2013-12-09 13:36:50

标签: ios uitabbarcontroller

我创建了一个TabBarController但它们的TabBarItems没有出现。

我做错了什么?因为我已经添加了视图控制器的tabBarItem,它们不会出现。

//Create Controllers
SBQNewsViewController *news=[[SBQNewsViewController alloc] initWithStyle:UITableViewStylePlain];
SBQFavoritesViewController *favs=[[SBQFavoritesViewController alloc] initWithStyle:UITableViewStylePlain];

//Create NavigationControllers
UINavigationController *newsNav=[[UINavigationController alloc] initWithRootViewController:news];
UINavigationController *favsNav=[[UINavigationController alloc] initWithRootViewController:favs];

//Create TabBarController
UITabBarController *tabReader=[[UITabBarController alloc] init];
tabReader.viewControllers=@[newsNav,favsNav];

self.window.rootViewController=tabReader;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;

Screen

并且tabBarItems添加了:

进入SBQNewsViewController:

#import "SBQNewsViewController.h"

   @implementation SBQNewsViewController

   - (id)initWithStyle:(UITableViewStyle)style
   {
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        self.tabBarItem.image = [UIImage imageNamed:@"Reportslc.png"];
        self.tabBarItem.title = @"Noticias";
    }
    return self;
   }

进入SBQFavoritesViewController:

#import "SBQFavoritesViewController.h"

  @interface SBQFavoritesViewController ()

  @end

  static NSString *CellIdentifier=@"CellIdentifier";

  @implementation SBQFavoritesViewController

  - (id)initWithStyle:(UITableViewStyle)style
  {
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        self.tabBarItem.image = [UIImage imageNamed:@"Favoritelc.png"];
        self.tabBarItem.title = @"Favoritos";
    }
    return self;
  }

3 个答案:

答案 0 :(得分:0)

您尚未在代码中添加tabBarItem标题。使用tabBarItem.title并设置一些标题以查看标签栏..

答案 1 :(得分:0)

我将Items设置为didFinishLaunchingWithOptions,现在可以正常使用

UITabBarItem *itemsNews=[tabReader.tabBar.items objectAtIndex:0];
    [itemsNews setTitle:@"Noticias"];

UITabBarItem *itemsFavs=[tabReader.tabBar.items objectAtIndex:1];
    [itemsFavs setTitle:@"Favoritos"];

谢谢Bhumeshwer katre!

答案 2 :(得分:0)

而不是设置tabBarItem.title尝试设置screentitle:

self.title = @"Favoritos";