views:

301

answers:

2

I am using multiple controller during launch of an application in app delegate. One controller is for registration and the second controller is tabbar. tabbar was loading fine but when I pushed registration controller on window, contents went up by 20 units and I have good white blank screen at bottom. Therefore I recreated frame of my registration view controller in its viewdidload method and slided it 20 units down. The code is

self.view.frame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height);

and code in my app delegate for launch application was

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    if (![self accountExists]) {
                //code if account does not exists on iphone app database
        self.registerAccount = [[registerViewController alloc] initWithNibName:@"registerViewController" bundle:nil];
        [window addSubview:registerAccount.view];
    }
    else if([self autoLoginForAnyAccount]){
        //code for autologin to app
    }
    else {
        self.tabBarController.selectedIndex = 1;
        self.tabBarController.delegate = self;
        [window addSubview:tabBarController.view];
    }
    [window makeKeyAndVisible];
    return YES;
}

if anyone knows why there is a white space at bottom when registration controller is pushed then please share it with me.

A: 

The 20px space corresponds to the size of the status bar. Are you removing the status bar in code, but have it set to be there in a nib ?

Andiih
+1  A: 

I figure out the issue but not the reason. Issue was size of the window i.e. In my code i was creating instance of registerViewController therefore its size was size of the window minus size of the status bar(since it is a view controller which must be displayed below status bar). When i pushed registerViewController onto window then because of some reason (i dont know why) view controller failed to recognize status bar in the header and 20px of registerViewController was displaying behind status bar. then I tried code registerAccount.view.frame = window.frame; which sets the frame of my registration controller equals to window controller. This removed blank white screen at the bottom and view now taking whole of the window size but still 20px was behind status bar since my view controller was blind to see existance of status bar. I tried to remove status bar using code which showed my whole controller on the screen but I wanted status bar at the top too.

I figure out my way by adding UIViewcontroller object in my mainWindow.xib file(just like my tab bar controller) and I pointed its class to be registerViewController and loaded nib of registerViewController. i also removed line self.registerAccount = [[registerViewController alloc] initWithNibName:@"registerViewController" bundle:nil];

and replaced in my delegate .h file registerViewController *registerAccount; with UIViewController *registerAccount; and in mainWindow.xib file I pointed my newly added view controller to this controller. Now everthing is working fine but I still dont know why viewcontroller failed to see status bar when I pushed instance of registerViewController. if anyone knows the reason then please share here with me.

Ayaz Alavi