问题
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