So, right now I had created a view-based application with 8 different views. I want it to show a tab bar on 3 of the views. This tab bar would have 3 items, which will allow the user to switch to the 3 said views.
How should I go about doing so? Thanks a lot.
AppDelegate.h
@interface LoginPageAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
LoginPageViewController *viewController;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet LoginPageViewController *viewController;
@property (nonatomic, retain) IBOutlet IBOutlet UITabBarController *tabBarController;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
RequestPage* requestPage = [[RequestPage alloc] init];
UIViewController *RequestPageView = [[UIViewController alloc] initWithRootViewController:requestPage];
StatusPage* statusPage = [[StatusPage alloc] init];
UIViewController *StatusPageView = [[UIViewController alloc] initWithRootViewController:statusPage];
NSArray* controllers = [NSArray arrayWithObjects:RequestPageView, StatusPageView, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
RequestPage.m
- (id)init {
self.title = @"Request Page";
UIImage* anImage = [UIImage imageNamed:@"3.png"];
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Request Page" image:anImage tag:2];
self.tabBarItem = theItem;
[theItem release];
return self;
}
You need to start with view based application. And then create a
UITabbarControllerin youappDelegatefile.Appdelegate.h
Appdelegate.m
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
in which you can set Tab name and image.
Update: