2010-11-22 48 views
0

我正在构建一个需要viewcontroller和tab bar控制器的应用程序。在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]; 

我仍然得到:

​​

回答

0

从一个tabbar应用程序开始。在您的应用程序委托的applicationDidFinishLaunchingWithOptions部分中,您将视图控制器添加到窗口中,并覆盖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];