0
votes

I am working on tab bar application in which i called navigation controller on following way The problem is i cannot able to oriented to Landscape mode. can anybody please say what i went wrong?

Regards, sathish

-(IBAction)click


{

    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];

    UINavigationController *localNavigationContriller;

    FavouritesViewController *master;
    master = [[FavouritesViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:master];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
     [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [master release];

    NeedViewController *need;
    need = [[NeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:need];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [need release];

    DontNeedViewController *dontneed;
    dontneed = [[DontNeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:dontneed];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [dontneed release];

    tabBarController.delegate=self;
    tabBarController.viewControllers = localControllersArray;
    [localControllersArray release];

    [[[UIApplication sharedApplication] keyWindow] addSubview:tabBarController.view];
}
2

2 Answers

1
votes

Listen dude u you have to override the shouldrotate function to YES in all the tab bar , like you have 3 tab bar in your app , go to there respective class and

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations.

    return YES;
}

in all the respective class of the tab bar... hope that help , if it does pray for me ...

0
votes

It's not possible to change the orientation for one view in a tabBar and not for another. If a TabBar is specified then all the subviews (tabs) must have the same orientation appearance. You must set the orientation in each ViewController and in the TabBarController.

So just add this in all the tabbar's main Controllers

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;

    return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

In your Case those controllers where this code is to be added are FavouritesViewController, NeedViewController & DontNeedViewController