Design Patterns:
The main patterns that you will use in simple cocoa touch based application are:
- Delegation
- Model View Controller
- Target Action
Example : In a normal application, application object tells its delegate(which is
Model View Controller : MVC sets out 3 roles for objects in an application
Model : Model object represents data.
Example :
- Space ship and rockets in a game.
- Todo items in a productive application.
- Circle and squares in a drawing application.
Controller : Controller object mediates between models and views.
Target Action :
The target-action mechanism enables a control object - that is, an object such as a button or slider - in response to a user event (such as a click or a tap), sends a message(the action) to another object (the target) that can interpret the message and handle it as an application specific instructions.
Xcode : Apple's IDE(Integrated development Environment).
Info.plist : Info.plist is a dictionary that contains information about the application such as its name and icon.
Bundle :
A Bundle is an abstraction of a location in the file system that groups code and resources that can be used in an application.
Forward declaration in Objective C:
This is a promise to the compiler that class will be defined some where else and that it needn't waste time checking for it now.
Forward declaration in Objective C : @class MyViewController.
Nib files : Nib files contains an archive of user interface elements (file extension will be .xib).Clicking on it opens the xib file in Interface builder.
NIB : NextStep Interface Builder
Interface Builder :
This application is used to create user interfaces. It does not create/generate source code, instead it allows you to manipulate object directly and then save those objects in an archive called nib files.
At runtime, when nib is loaded the objects are unarchived and restored to the state they were in when you saved the file including connection between them.
The Interface Builder document contains 4 items:
- File's owner proxy object.
- File's responder proxy object.
AppDelegate. - A Window.
The View Outlet : An outlet is just an attribute (typically an instance variable) that happens to connect to an item in a nib file.The outlet connection means that when the nib file is loaded and the UIView instance is unarchived, the view controller view instance variable is set to that view.
Note : You can look at - and make and break - an object's connection using an inspector panel.In interface builder document-click on files owner to display a translucent panel showing file's owner connections.
Application Bootstrapping:
If you create a project using template provided by Xcode already sets up the basic application environment.
It creates:
- Application object.
- Connects to the window server.
- Establishes the run loop and so on.
main function which is normally available in main.m is the starting point to iPhone application.
When user taps on the application then UIApplication looks at info.plist and loads the main lib file(file name that is associated with NSMainNibFile key in that plist). And following things will happen
- STEP 1 : Delegate creates view controller object and initializes it.
- STEP 2 : The Delegate asks its view controller for its view.
- STEP 3 : Finally delegate adds that view as a subview of the window.
Example code for each step:
STEP 1 : Delegate creates view controller object and initializes it:
view controller will be initialized with intWithNibName:bundle: method.
View controller object plays a central role in most iPhone applications.This is responsible for managing a view.
UIKit provides a special class - UIViewController - that encapsulates most of the default behavior you want from a view controller.You have to create a subclass to customize your behavior for your application.
Note : The View controller lasts for the life time of the application, so it is good practice to add it as an instance variable of the application delegate.
Disabling Status bar:
Added "Status bar is initially hidden" check box to info.plist and check the check box this will disables the status bar.
STEP 1 : Delegate creates view controller object and initializes it:
view controller will be initialized with intWithNibName:bundle: method.
MyViewController* aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]];
[self setMyViewController:aViewController];
[aViewController release];STEP 2 : The Delegate asks its view controller for its view.
UIView* controllerView = [myViewController view];STEP 3 : Delegate adds that view as a subview of the window.
[window addSubView : controllerView];View Controller Class:
View controller object plays a central role in most iPhone applications.This is responsible for managing a view.
UIKit provides a special class - UIViewController - that encapsulates most of the default behavior you want from a view controller.You have to create a subclass to customize your behavior for your application.
Note : The View controller lasts for the life time of the application, so it is good practice to add it as an instance variable of the application delegate.
Disabling Status bar:
Added "Status bar is initially hidden" check box to info.plist and check the check box this will disables the status bar.
IBOutlet : IBOutlet is a special keyword that is used only to tell Interface Builder to treat an instance variable or property as an outlet. It’s actually defined as nothing so it has no effect at compile time.
Example:
Example:
UILabel *label;
@property (monatomic, retain) IBOutlet UILable* label;
IBAction : IBAction is a special keyword that is used only to tell Interface Builder to treat a method as an action for target/action connections. It’s defined to void.
Example:
Use following code to get access to AppDelegate:
iPhone OS Graphics Overview:
Core Animation is fundamental to the iPhone graphics sub-system.
Every UIView object in your application is backed by a Core Animation layer.As various layers update their contents, they are animated and composited by Core Animation and presented to the display.
OpenGL ES is also a client of Core Animation.To use OpenGL ES to draw to the screen, your application creates a UIView class backed by a special Core Animation layer, CAEAGLLayer object.
CAEAGLLayer : A CAEAGLLayer object is aware of OpenGL ES and can be used to create rendering targets that acts as part of CoreAnimation.
Note: In your application you can create screens using both OpenGL ES layer and non-OpenGL ES layer drawing , but this hits performance.
Example:
- (IBAction)changeGreeting:(id)sender;Getting access to AppDelegate instance :
Use following code to get access to AppDelegate:
[[UIApplication sharedApplication] delegate]
iPhone OS Graphics Overview:
Core Animation is fundamental to the iPhone graphics sub-system.
Every UIView object in your application is backed by a Core Animation layer.As various layers update their contents, they are animated and composited by Core Animation and presented to the display.
OpenGL ES is also a client of Core Animation.To use OpenGL ES to draw to the screen, your application creates a UIView class backed by a special Core Animation layer, CAEAGLLayer object.
CAEAGLLayer : A CAEAGLLayer object is aware of OpenGL ES and can be used to create rendering targets that acts as part of CoreAnimation.
Note: In your application you can create screens using both OpenGL ES layer and non-OpenGL ES layer drawing , but this hits performance.

No comments:
Post a Comment