Simple Tab Bar Controller with UINavigation Controller in iPhone
1. Create simple Tab bar application with navigation controller like a above image for that we have to create new
project and select simple View-base application and give name TabBarWithNavigation.
2. Now we have first modify MainWindow.xib file and drag one tab bar controller from liberary shown below image
and select View Controller and delete and drag one Navigation Controller from liberary becouse we s.
3. Now we have define IBOutlet for Tab Bar Controller and Navigation Controller in
TabBarWithNavigationAppDelegate.h file and connect it to our Tab Bar Controller and Navigation Controller in
Mainwindow.xib file.
#import <UIKit/UIKit.h>
@interface TabBarWithNavigationAppDelegate: NSObject
<UIApplicationDelegate>
{
UITabBarController * tabController;
UINavigationController * navController;
}
@property (nonatomic, retain) IBOutlet UINavigationController * navController;
@property (nonatomic, retain) IBOutlet UITabBarController * tabController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
4.Now modify TabBarWithNavigationAppDelegate.m file and synthesize UINavigation Controller and
UITabBarController and add Tab Bar Controller in window and also dealloc both.
#import "NavigationControllerAppDelegate.h"
@implementation TabBarWithNavigationAppDelegate
@synthesize window=_window;
@synthesize navController;
@synthesize tabController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:tabController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[tabController release];
[navController release];
[_window release];
[super dealloc];
}
@end
5. Now Create file called FirstView and SecondView with .h .m and .xib file and modify as given below. Create SecondView object in FirstView.h file.and create one IBAction for next button.
FirstView.h
#import <UIKit/UIKit.h>
#import "SecondView.h"
@interface FirstView : UIViewController
{
SecondView * secondView;
}
-(IBAction)moveToNextView:(id)sender;
@end
6. Now Modify FirstView.m file and drag one UILabel from liberary and set text First View to label.
#import "FirstView.h"
@implementation FirstView
-(IBAction)moveToNextView:(id)sender
{
secondView=[[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
}
- (void)viewDidLoad
{
self.navigationItem.title=@"FirstView";
UIBarButtonItem * next=[[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStylePlain
target:self action:@selector(moveToNextView:)];
self.navigationItem.rightBarButtonItem=next;
[super viewDidLoad];
}
@end
7. Now In SecondView.xib file drag one label from liberary and no need to modify .h and .m file and back button
is automatically created in UINavigation bar now build your project by pressing ctrl+b and run with ctrl+r
TabBarWithNavigationAppDelegate.h file and connect it to our Tab Bar Controller and Navigation Controller in
Mainwindow.xib file.
#import <UIKit/UIKit.h>
@interface TabBarWithNavigationAppDelegate: NSObject
<UIApplicationDelegate>
{
UITabBarController * tabController;
UINavigationController * navController;
}
@property (nonatomic, retain) IBOutlet UINavigationController * navController;
@property (nonatomic, retain) IBOutlet UITabBarController * tabController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
4.Now modify TabBarWithNavigationAppDelegate.m file and synthesize UINavigation Controller and
UITabBarController and add Tab Bar Controller in window and also dealloc both.
#import "NavigationControllerAppDelegate.h"
@implementation TabBarWithNavigationAppDelegate
@synthesize window=_window;
@synthesize navController;
@synthesize tabController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:tabController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[tabController release];
[navController release];
[_window release];
[super dealloc];
}
@end
5. Now Create file called FirstView and SecondView with .h .m and .xib file and modify as given below. Create SecondView object in FirstView.h file.and create one IBAction for next button.
FirstView.h
#import <UIKit/UIKit.h>
#import "SecondView.h"
@interface FirstView : UIViewController
{
SecondView * secondView;
}
-(IBAction)moveToNextView:(id)sender;
@end
6. Now Modify FirstView.m file and drag one UILabel from liberary and set text First View to label.
#import "FirstView.h"
@implementation FirstView
-(IBAction)moveToNextView:(id)sender
{
secondView=[[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
}
- (void)viewDidLoad
{
self.navigationItem.title=@"FirstView";
UIBarButtonItem * next=[[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStylePlain
target:self action:@selector(moveToNextView:)];
self.navigationItem.rightBarButtonItem=next;
[super viewDidLoad];
}
@end
7. Now In SecondView.xib file drag one label from liberary and no need to modify .h and .m file and back button
is automatically created in UINavigation bar now build your project by pressing ctrl+b and run with ctrl+r
Related Posts :
1. UIText Field with default and number pad keybord
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. Create simple UINavigation controller in iPhone
5. How to install Mac os x in windows PC
2. UIActionSheet button event in iphone
3. Create combobox using UIActionsheet
4. Create simple UINavigation controller in iPhone
5. How to install Mac os x in windows PC
HTML Comment Box is loading comments...