switch between viewcontroller and Tab bar controller
I am building an application which needs both a viewcontroller and a tab bar controller.
When I start the application it should load view controller (which is login screen) and from there I need to go to the tabbar controller view where the actual application starts.
Here is what I have tried:
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;
}
I am receiving these errors and warnings. What am I doing wrong?
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'
Update: I figured out one error:
LoginController = [[LoginViewController alloc] init];
But in this statement:
[window LoginController.view];
I still get:
error: expected ']' before '.' token
Start with a tabbar app. In the applicationDidFinishLaunchingWithOptions portion of your app delegate you'll add your viewcontroller to the window, covering up the tabbar and everything else. It'll look like this:
// 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];
精彩评论