tags:

views:

25

answers:

1

EDIT 1: changed the code to:

delegate.h:

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    ViewController *viewController;
    UIImageView *splashView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ViewController *viewController;
@property (nonatomic, retain) IBOutlet UIImageView *splashView;

- (void)removeSplash;

@end

delegate.m:

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

@synthesize window;
@synthesize viewController;
@synthesize splashView;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Splash" ofType:@"png"]];
    [window addSubview:splashView];
    [window bringSubviewToFront:splashView];
    [window makeKeyAndVisible];

    [self performSelector:@selector(removeSplash) withObject:nil afterDelay:5.0];

    [window addSubview:viewController.view];

    return YES;
}

- (void)removeSplash {
    [splashView removeFromSuperview];
    [splashView release];
}

- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}

@end

EDIT 2:

when i use:

splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Splash" ofType:@"png"]];
if (splashView.image == nil) {
    NSLog(@"splashView is nil");
}

it logs "splashView is nil"

My Viewcontroller is empty, just for debugging purposes. Thnx in advance!

+2  A: 

As you probably already know, splash screens are discouraged. Since your image is Default.png, isn't it already being shown on app launch automatically?

In any case, the sleep() call is probably blocking the UI. Remove the sleep() and move the statements after it (the removeFromSuperview, etc) to another method in the app delegate. Call this method using performSelector:withObject:afterDelay:. Put the performSelector call where you currently have the sleep call.

Also, you should use the didFinishLaunchingWithOptions method instead of the old applicationDidFinishLaunching method.

aBitObvious
Although splash screens are discouraged, if your app takes more than a second or two to load I think it is good UI to make sure it doesn't look like it can be interacted with. A smaller alert splash-screen over your UI looks pretty good.
Peter DeWeese
The Default.png doesn't work automatically when i just put it in my resource folder. Im trying your other solutions as we speak.
lugte098
Also move the `[window addSubview:viewController.view];` to the `removeSplash` method (make it the last line in that method).
aBitObvious
the background turned from black to white, but still no image
lugte098
Is the background of your viewcontroller white? Did you move the adding of the viewcontroller.view to removeSplash? Is there a 5 second delay? Make sure image is actually loading by checking if splashView.image is nil.
aBitObvious
first the background is white(first it was black), then after 5 seconds it turns grey(background of the viewcontroller). I did move the viewcontroller.view to removeSplash. Where do i need to make this nil check?
lugte098
After the imageWithContentsOfFile line. Make sure you've added that image to your project and it is named exactly Splash.png.
aBitObvious
Im very sure it is in my resource folder and in the project and named exactly Splash.png
lugte098
The white background is the splashView object with no image. It is not able to load Splash.png for some reason. Try removing it from the project and add back. Try another image you have in your project that you are using for another imageview.
aBitObvious
ok any other image works just fine. can't figure out why my Splash.png doesn't
lugte098
Ok so i opened the image in photoshop and i saved it again as Splash.png and now it works for some strange reason.... Anyway you've been a great help and because of you i've been able to solve this problem, THNX
lugte098
Sure no problem. Glad it worked out.
aBitObvious