We have added a UITabBarController programmatically in our app. We added 3 UINavigationController in UITabViewController like below code:

```
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:36.0/255.0 green:179.0/255.0 blue:125.0/255.0 alpha:1.0];

FirstViewController *VC1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navControllerFirst = [[UINavigationController alloc]initWithRootViewController:VC1];
UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"First"] tag:0];
navControllerFirst.tabBarItem = item1;

SecondViewController *VC2 = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
UINavigationController * navControllerSecond = [[UINavigationController alloc]initWithRootViewController:VC2];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"Second" image:[UIImage imageNamed:@"Second"] tag:0];
navControllerSecond = item2;

ThirdViewController *callTransactionsNew=[[ThirdViewController alloc]initWithStyle:UITableViewStyleGrouped];
UINavigationController * navControllerThird = [[UINavigationController alloc]initWithRootViewController:callTransactionsNew];
UITabBarItem *item3 = [[UITabBarItem alloc] initWithTitle:@"Third" image:[UIImage imageNamed:@"Third"] tag:0];
navControllerThird = item3;

NSArray* controllers = [NSArray navControllerFirst, navControllerSecond, navControllerThird,nil];
self.tabBarController.viewControllers = controllers;
self.tabBarController.delegate = self;
self.tabBarController.view.frame = self.view.frame;

[self.tabBarController willMoveToParentViewController: self];
[self addChildViewController: self.tabBarController];
[self.view addSubview: self.tabBarController.view];
[self.tabBarController didMoveToParentViewController:self];

```

In didSelectViewController in TabBar we added below code. This code rotates FirstViewController to portrait mode if the user is in landscape mode in any other tab and then he taps on first tab.

```
[UIViewController attemptRotationToDeviceOrientation];
if([theTabBarController.viewControllers indexOfObject:viewController] == 0) {
    SEL sel = NSSelectorFromString(@"setOrientation:");
    if([[UIDevice currentDevice] respondsToSelector:sel]) {
      #pragma clang diagnostic push
      #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
      [[UIDevice currentDevice] performSelector:sel withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
      #pragma clang diagnostic pop
   }
}

```

Our requirement:

We want to fix the orientation of FirstViewController only to portrait. It shall not rotate. Rest UIViewControllers can be rotate in both landscape and portrait.
Can anyone please help?