1

Im trying to show a UIViewController for 2 seconds before the UITabBarController, i know i have to make it fromm my appdelegate. Ive tried by first assigning my self.window.rootviewcontroller to my UIViewController and with a scheduled timer after 2 seconds reassigning my self.window.rootviewcontroller to my UITabViewController.

The problem is that when i test it, my viewcontroller shows up, but after the 2 seconds the app crashes.

This is my LaMetro_88AppDelegate.h

@interface LaMetro_88AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
    UIView *startupView;
    NSTimer *timer;

    UIViewController *LoadingViewController;
    UITabBarController *tabBarController;
}

-(void)changeView;
@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UIViewController *LoadingViewController;

@end

This is my LaMetro_88AppDelegate.m

@implementation LaMetro_88AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
@synthesize LoadingViewController = _LoadingViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
     self.window.rootViewController = self.LoadingViewController;

    timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(changeView:) userInfo:nil repeats:NO];

    [self.window makeKeyAndVisible];
    return YES;
}

-(void)changeView
{

    self.window.rootViewController = self.tabBarController;  

}
Lord Pepito
  • 291
  • 3
  • 15
  • How are you adding the new view controller? Try first adding it as a subview to your `window`, and _then_ setting the `rootViewController` to the new view controller. But if you're just showing the `UIViewController` for 2 seconds, just add it to the `UITabBarController`'s view and remove it after two seconds. – sooper Dec 11 '12 at 23:49
  • I updated the question and thats what i have in my code. I added it in my MainViewController.xib i placed a view controller and a view inside it. – Lord Pepito Dec 11 '12 at 23:59

1 Answers1

0

Your app is crashing because your selector has a colon after it (changeView:) whereas, the method does not. Just delete that colon. Also, there is no need to have a ivar for the timer or even to assign the timer creation to anything -- that line can just be:

[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(changeView) userInfo:nil repeats:NO];
rdelmar
  • 103,982
  • 12
  • 207
  • 218