从UIViewController切换到TabBarController

时间:2012-12-12 00:05:47

标签: iphone ios uiviewcontroller uitabbarcontroller switch-statement

  

可能重复:
  Switching from UIViewController to UITabBarController

我试图在UITabBarController之前显示一个UIViewController 2秒,我知道我必须从我的appdelegate开始。我已经尝试过第一次将我的self.window.rootviewcontroller分配给我的UIViewController并在2秒后将我的self.window.rootviewcontroller重新分配给我的UITabViewController。

问题在于,当我测试它时,我的viewcontroller显示,但在2秒后应用程序崩溃。

这是我的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

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

}

2 个答案:

答案 0 :(得分:0)

因为changeView方法不接受参数,所以它的方法签名不包含冒号。将您的选择器更改为changeView而不使用冒号:

@selector(changeView)

答案 1 :(得分:0)

改变这个:

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

对此:

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