3

I am having trouble with the background in my modal UIViewController displaying before the animation begins. I have a simple UINavigationController which loads a UIViewController. I then present the UINavigationController via a presentModalViewController call which slides it up from below. Within the UIViewController's loadView method I set up the standard self.view and create a background UIImageView. This background loads, but only after the modal animation is complete. I have done this type of thing many times before and remember having this issue once but can't for the life of me find what my "magic" solution was.

My code is below:

PhotoVideoViewController *photo = [[PhotoVideoViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:photo];

NSLog(@"start present modal view controller");

[self.navigationController presentModalViewController:nav animated:YES];
[photo release];
[nav release];

PhotoVideoViewController loadView:

- (void)loadView {
    UIView *myview = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.view = myview;
    [myview release];

    NSLog(@"background loading");

    UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background-main.png"]];
    background.frame = CGRectMake(0, -45, 320, 480);
    [self.view addSubview:background];
    [background release];
}

The "start present modal view controller" displays in the log BEFORE "background loading" log shows up which tells me something is wrong obviously. I have tried to put the [photo release]; before the presentModalViewController but it does NOT resolve the issue.

I have also done my research here and none of the other posts answer my issue:

UINavigationController with presentModalViewController

UINavigationController and presentModalViewController

  • Both of these apply to the proper way to use the UINavigationController as a modal screen with a UIViewController within it.

Any help is greatly appreciated. I've tried several permutations and am at a loss. It has the be the right order of things, but I'm obviously not getting the perfect order in my code.

Thank you in advance!

J

Community
  • 1
  • 1
seejaneworkit
  • 236
  • 1
  • 6

1 Answers1

1

Resolved the issue - simple mistake. Had a background set but was using "jpg" rather than "png" ;) Lots of time wasted on this one sadly. Its always the typos that get me.

seejaneworkit
  • 236
  • 1
  • 6