Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPhone - After dismissing Modal View Controller - gap is left at top of page

Tags:

When starting the app, if the user doesn't have login information stored, I want to display a modal view controller to force the entry of this information. I found through trial and error, that this had to occur in viewDidAppear of my root view controller. I tried to put it in viewDidLoad and viewWillAppear, but those didn't work unless I assigned the view of the root view controller to the view of the navigation controller used in the modal which then caused other issues...

So I have:

- (void)viewDidAppear:(BOOL)animated {      NewAccountViewController *newAccountViewController = [[[NewAccountViewController alloc] initWithNibName:@"NewAccountViewController" bundle:nil] autorelease];       UINavigationController *accountNavigationController = [[UINavigationController alloc] initWithRootViewController:newAccountViewController];   [self presentModalViewController:accountNavigationController animated:YES];        } 

And in the newAccountViewController I have a simple navigation item button that dismisses the modal view controller with dismissModalViewController.

This all works and when the modal is dismissed a view in a navigation controller is visible with its navigation item title at the top....

But there is a white gap about the same size as the status bar between the status bar and the top of the blue navigation item bar. If I don't do the modal, then the gap is never there. It only occurs after the modal is presented and dismissed. I've tried doing animated:NO on both the present and dismissModalViewController. I've also tried not using the navigation controller in the modal, and that did nothing as well. Any ideas would be great! Thanks.

like image 852
Brian Avatar asked Aug 13 '09 16:08

Brian


2 Answers

I had the same problem. My solution was to temporarily close the status bar just before switching views:

- (void) temporarilyHideStatusBar {   [[UIApplication sharedApplication] setStatusBarHidden:YES];   [self performSelector:@selector(showStatusBar) withObject:nil afterDelay:0]; } - (void) showStatusBar {   [[UIApplication sharedApplication] setStatusBarHidden:NO]; }  // Use these by calling the hide function just before a broken view switch: [self temporarilyHideStatusBar]; [self doViewSwitch];  // No need to call [self showStatusBar]; explicitly. 

I experimented with other code-based solutions, and I like this one the best because it works 100% of the time - some of my frame-based solutions only worked most of the time - and because it has minimal user-visible effects.

I suspect this is an Apple bug, and it would be nice to hear the official word from them on the best workaround.

like image 90
Tyler Avatar answered Oct 04 '22 04:10

Tyler


Turns out this was happening because I was calling my modalviewcontroller on the current view controller, but my view controller already had a another view controller loaded as a subview. Once I changed it to make the view controller in the subview, load the modal, then it went away. Thanks for all your help.

like image 20
Brian Avatar answered Oct 04 '22 04:10

Brian