在viewcontroller和Tab栏控制器之间切换

时间:2010-11-22 04:59:51

标签: objective-c iphone

我正在构建一个需要viewcontroller和tab bar控制器的应用程序。

当我启动应用程序时,它应该加载视图控制器(这是登录屏幕),然后我需要转到实际应用程序启动的tabbar控制器视图。

以下是我的尝试:

appdelegate.h

#import <UIKit/UIKit.h>

@interface IeAppDelegate
        : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

    UIWindow *window;

    UITabBarController *tabBarController;

    UIViewController *LoginController;
}

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

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

@property (nonatomic, retain) IBOutlet UIViewController *LoginController;

@end

appdelegate.m

@synthesize window;

@synthesize tabBarController;

@synthesize LoginController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the tab bar controller's view to the window and display.

    LoginController = [[LoginController alloc] init];
    [window LoginController.view];

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

    return YES;
}

我收到这些错误和警告。我做错了什么?

warning: 'UIViewController' may not respond to '-alloc'
warning: (Messages without a matching method signature
warning: will be assumed to return 'id' and accept
warning: '...' as arguments.)
error: expected ']' before '.' token
warning: 'UIWindow' may not respond to '-LoginController'

更新:我发现了一个错误:

LoginController = [[LoginViewController alloc] init];

但在这句话中:

[window LoginController.view];

我仍然得到:

error: expected ']' before '.' token

1 个答案:

答案 0 :(得分:0)

从标签栏应用开始。在app delegate的applicationDidFinishLaunchingWithOptions部分中,您将把viewcontroller添加到窗口,覆盖tabbar和其他所有内容。它看起来像这样:

// Initialize your login view controller
yourLoginViewController = [[YourLoginViewController alloc] init];

// Add in the tab controller 
// (this code should already be there if you started with the template)
[window addSubview:tabcontroller.view];

// In front of that add in your login view controller
[window yourLoginViewController.view];

// Finally, display the whole thing (this should also already be there)
[window makeKeyAndVisible];