Simple UINavigation Controller with two different view.
Open your xcode and create Navigation-base application or you can create View-base application. I have created View-base application and right click on project and create new View Controlller classes and give name FirstView and SecondView.
1. Navigation controller application you can work directly in Interface builder or you can work with code good and simple way
is by using code.
2. After creating View-base application look at your in your MainWindow.xib file drag UINavigation Controller from liberary
and go for code in NavigationControllerAppDelegate.h file create one IBOutlet for UINavigationController and also define
property for it than after open NavigationControllerAppDelegate.m file and synthesize your property. After complition of this
task connect your IBOutlet to you UINavigationController in xib file
#import <UIKit/UIKit.h>
@interface NavigationControllerAppDelegate : NSObject <UIApplicationDelegate>
{
IBOutlet UINavigationController * navController;
}
@property (nonatomic, retain) IBOutlet UINavigationController * navController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
3. Now open your NavigationControllerAppDelegate.m file and modify applicationdidFinishLaunchingWithOption and dealloc
method.
#import "NavigationControllerAppDelegate.h"
@implementation NavigationControllerAppDelegate
@synthesize window=_window;
@synthesize navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
//Release memory of UINavigation Controller
[navController release];
[_window release];
[super dealloc];
}
@end
3. Open your MainWindow.xib file and object window look at Navigation Controller drop down and modify view controller class
property in inspector pan to FirstView which we have created previosly and open FirstView.h file import SecondView.h file and
define one object of SecondView.Also define IBAction for go to next view like in above image.
#import <UIKit/UIKit.h>
#import "SecondView.h"
@interface FirstView : UIViewController
{
SecondView * secondView;
}
-(IBAction)moveToNextView:(id)sender;
@end
4.Now modify FirstView.m file as given below
#import "FirstView.h"
@implementation FirstView
//moveToNextView Method allocate secondView object and pushViewController secondView animated:YES is for UI Animation
-(IBAction)moveToNextView:(id)sender
{
secondView=[[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
}
- (void)viewDidLoad
{
self.title=@"First View";
UIBarButtonItem * next=[[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self
action:@selector(moveToNextView:)];
self.navigationItem.rightBarButtonItem=next;
[super viewDidLoad];
}
@end
5. Design your Interface Builder like SecondView image and modify SecondView.m file modify viewDidLoad methos set title of
navigation controller and you can see back button for first view by default created.
self.title=@"Second View";
6. Now Your project is ready to build and run in simulator.
is by using code.
2. After creating View-base application look at your in your MainWindow.xib file drag UINavigation Controller from liberary
and go for code in NavigationControllerAppDelegate.h file create one IBOutlet for UINavigationController and also define
property for it than after open NavigationControllerAppDelegate.m file and synthesize your property. After complition of this
task connect your IBOutlet to you UINavigationController in xib file
#import <UIKit/UIKit.h>
@interface NavigationControllerAppDelegate : NSObject <UIApplicationDelegate>
{
IBOutlet UINavigationController * navController;
}
@property (nonatomic, retain) IBOutlet UINavigationController * navController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
3. Now open your NavigationControllerAppDelegate.m file and modify applicationdidFinishLaunchingWithOption and dealloc
method.
#import "NavigationControllerAppDelegate.h"
@implementation NavigationControllerAppDelegate
@synthesize window=_window;
@synthesize navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
//Release memory of UINavigation Controller
[navController release];
[_window release];
[super dealloc];
}
@end
3. Open your MainWindow.xib file and object window look at Navigation Controller drop down and modify view controller class
property in inspector pan to FirstView which we have created previosly and open FirstView.h file import SecondView.h file and
define one object of SecondView.Also define IBAction for go to next view like in above image.
#import <UIKit/UIKit.h>
#import "SecondView.h"
@interface FirstView : UIViewController
{
SecondView * secondView;
}
-(IBAction)moveToNextView:(id)sender;
@end
4.Now modify FirstView.m file as given below
#import "FirstView.h"
@implementation FirstView
//moveToNextView Method allocate secondView object and pushViewController secondView animated:YES is for UI Animation
-(IBAction)moveToNextView:(id)sender
{
secondView=[[SecondView alloc]initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
}
- (void)viewDidLoad
{
self.title=@"First View";
UIBarButtonItem * next=[[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStylePlain target:self
action:@selector(moveToNextView:)];
self.navigationItem.rightBarButtonItem=next;
[super viewDidLoad];
}
@end
5. Design your Interface Builder like SecondView image and modify SecondView.m file modify viewDidLoad methos set title of
navigation controller and you can see back button for first view by default created.
self.title=@"Second View";
6. Now Your project is ready to build and run in simulator.
Releted 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 on 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 on windows pc
HTML Comment Box is loading comments...