从UIViewController切换到UITabBarController [英] Switching from UIViewController to UITabBarController
问题描述
我试图在UITabBarController之前显示UIViewController 2秒,我知道我必须从我的appdelegate开始。我已经尝试过首先将我的self.window.rootviewcontroller分配给我的UIViewController,并在2秒后将我的self.window.rootviewcontroller重新分配给我的UITabViewController。
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.
问题就是当我测试它时,我的viewcontroller出现了,但是在2秒之后应用程序崩溃了。
The problem is that when i test it, my viewcontroller shows up, but after the 2 seconds the app crashes.
这是我的LaMetro_88AppDelegate.h
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
这是我的LaMetro_88AppDelegate.m
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;
}
推荐答案
您的应用崩溃,因为你的选择器后面有一个冒号(changeView :),而方法却没有。只需删除该冒号即可。此外,没有必要为定时器设置一个ivar,甚至不需要将定时器创建分配给任何东西 - 该行只能是:
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];
这篇关于从UIViewController切换到UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!