Introduction
In iPhone Application Development first of all we use Xcode which is a suite of tools for developing software on Mac OS X. Xcode creates a lots of code and components for us. Let us have a detailed look into this code.
- Delegate.h
- Delegate.m
- UIViewController.h
- UIViewController.m
These are the classes of a Single View Application created by Xcode. All these classes are Objective C files, each playing a designated role in the project. In Objective C the ".h" files are used for decelerations and the ".m" files have the implementation details. So the two classes Delegate and View Controller are also divided into respective ".h" and ".m" files.
To understand these classes we use an example.
First I give you a short introduction about the Delegate Class and View Controller
Delegate Class is a powerful class in iPhone apps development; without it applications cannot running properly. This class actually starts the application and exists throughout the life cycle of the application. It work as a controller class and it acts as a Shell which enables the application. The application passes messages through an object to the delegate which are handled and acted upon by it.
View Controller is very specific to view-based applications that we have selected. Before we discuss the View Controller we must tell you that a view is something that the user interacts directly with during execution of the application. It is basically used to create a design view using xib (Xcode Interface Builder), in which we create buttons, Image Views, UItableviews, Picker Views etc. conveniently using Drag and Drop.
AppDelegate.h
@class HelloUniverseController ;
@interface HelloUniverse AppDelegate : NSObject <UIApplicationDelegate>
{ UIWindow *window;
HelloUniverseController *viewController; }
@property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutletHelloUniverseController *viewController;
@end |
AppDelegate.m
#import "HelloUniverse AppDelegate.h" #import "HelloUniverseController.h "
@implementationHelloUniverse AppDelegate
@synthesize window; @synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application { [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } @end |
ViewController.h
#import <UIKit/UIKit.h> @interface HelloUniverseController : UIViewController { } @end |
ViewController.m
#import "HelloUniverseController.h "
@implementationHelloUniverseController
////Some methods
- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use. }
- (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; }
- (void)dealloc { [super dealloc]; }
@end |
It is only a format of the code is used in iPhone apps Development. One thing to always remember when you develop for iPhone is that we add multiple views in a single window but the delegate class is only one in the entire application. The Delegate class is automatically built when we create a Xcode project but if you want to create your own Delegate class or method then you do it manually.