Ravi
Ravi

Reputation: 1759

View containing navigation bar and tab bar is shifted some 4mm downwards

In my app from a login screen I am navigating to a class say classA, like this:

classA *objUserHome = [[classA alloc]init];
        [self presentModalViewController:objUserHome animated:YES];
        [objUserHome release];

And ClassA is having a navigating bar and a tabbar (5 tabs in it), I have created my tab bar programmatically like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Create tab bar controller and navigation bar controller
    
    tabBarController = [[UITabBarController alloc] init];
    
    NSMutableArray *arrControllers = [[NSMutableArray alloc] initWithCapacity:5];
    
    //Add PunchClock to tab View Controller
    PunchClock* objPunchClock = [[PunchClock alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objPunchClock];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objPunchClock release];
    
    //Add Time_Sheet to tab View Controller
    Time_Sheet* objTime_Sheet = [[Time_Sheet alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objTime_Sheet];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objTime_Sheet release];
    
    //Add PTO to tab View Controller
    PTO* objPTO = [[PTO alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objPTO];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objPTO release];
    
    //Add PunchClock to tab View Controller
    CrewPunch* objCrewPunch = [[CrewPunch alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objCrewPunch];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objCrewPunch release];
    
    //Add PunchClock to tab View Controller
    Reports* objReports = [[Reports alloc] initWithTabBar];
    NavigationController = [[UINavigationController alloc] initWithRootViewController:objReports];
    NavigationController.navigationBar.tintColor = [UIColor brownColor];
    [arrControllers addObject:NavigationController];
    [NavigationController release];
    [objReports release];
    
    // Add this view controller array into the tab bar
    
    //self .viewControllers = arrControllers;
     tabBarController .viewControllers = arrControllers;
   
    [arrControllers release];
    [self.view addSubview:[tabBarController view]];
    
   
}

And ClassA is inherited from UIViewController

Now the problem is, after navigating to classA, view of classA is shifted some 4mm downwards per the image below. Why is it so? How can I fix this?

like this

Upvotes: 1

Views: 472

Answers (4)

Sean Lintern
Sean Lintern

Reputation: 3141

When using storyboards and Modal Transition between 2 or more views you can encounter an error similar to the above.

If you use Modal Transition from ViewControllerA to ViewControllerZ and then attempt to Modal Transition from ViewControllerZ back to ViewControllerA sometimes the view of ViewControllerA gets pushed down the Window slightly.

This can be prevented using:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

On ViewControllerZ to go back to ViewControllerA from an event on ViewControllerZ

Upvotes: 1

Ravi
Ravi

Reputation: 1759

After a long research i finally fixed this issue just by inheriting the class from UINavigationController instead of UIViewControler

Upvotes: 0

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

Try as below

[self.navigationController.view addSubview:[tabBarController view]];

Upvotes: 0

Sanchit Paurush
Sanchit Paurush

Reputation: 6162

You might have chosen some top bar in your Interface Builder or XIB file and additionally set the navigation bar. Dont choose any top bar in the XIB file.

Upvotes: 0

Related Questions