Switching from UIViewController to UITabBarController

China☆狼群 提交于 2019-12-02 09:04:31

问题


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;  

}

回答1:


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];


来源:https://stackoverflow.com/questions/13830375/switching-from-uiviewcontroller-to-uitabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!