ipalibowhyte
ipalibowhyte

Reputation: 1563

How to display all tabBar titles in ios7

Basically i cant get to display all tabBar Items when i run my app, just the first view controller is displayed:

enter image description here

I literally have to click on a tab to display its Item:

enter image description here

This my code in Appdelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Initialize window
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

    // Set background colors for both NavBar and TabBar
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.157 green:0.718 blue:0.553 alpha:1]];
    [[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:0.141 green:0.216 blue:0.263 alpha:1]];

    // Initialize your five tab controllers.  with each tab has its own navigation controller
    HomePageView *homePageView = [[HomePageView alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];

    ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];

    FeedViewController *feedViewController=[[FeedViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];

    ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
    UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];

    RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
    UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];

    // initialize tabbarcontroller,set your viewcontrollers and change its color.
    self.tabC = [[UITabBarController alloc]init];
    NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
    [self.tabC setViewControllers: controllers animated:NO];
    [_window addSubview:self.tabC.view];

    // Show window
    [self.window makeKeyAndVisible];


    return YES;
}

Upvotes: 0

Views: 75

Answers (1)

rdelmar
rdelmar

Reputation: 104082

I'm guessing that you're setting the titles in the viewDidLoad or viewDidAppear methods of the controllers. That won't work, because, while all the controllers are instantiated in the app delegate, only the controller at index 0 has its view loaded, and thus viewDidLoad will not be run for the other controllers. Instead, you should set the titles on the navigation controllers in the app delegate,

ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
nav2.tabBarItem.title = @"Profile";

Upvotes: 1

Related Questions