The MVC pattern is certainly the most famous one.
It allows to dispatch the work in 3 concepts: The Model, the View and the Controller.
This concept exists in all programming languages.
So it's easy, when you understood it, to apply your knowledge with all others languages.
That's why this design pattern is really important for a good developer, and I am sure you are one of them.
Let's beginning by the Controller.
In Objective-C, the ViewController's header (the .h) must import the UIKit/UIKit.h.
#import <UIKit/UIKit.h>
The ViewController inherits from the UIViewController.
@interface BadProgViewController : UIViewController
The interface must have all properties used in the method implementation (the .m). This is a protocol.
{ UILabel *bpLabel; UITextField *bpTextField; }
The properties have to be declared with the keyword @property.
@property UILabel *bpLabel; @property UITextField *bpTextField;
The file finishes with the keyword @end.
@end
The complete header file.
As the header, the methods have their own file, called .m.
In our case BadProgViewController.m.
The method file has to import the corresponding header.
#import "BadProgViewController.h"
The implementation keyword has to be used in conjunction with the name of the file.
@implementation BadProgViewController
The properties can be synthesize.
@synthesize bpLabel; @synthesize bpTextField;
Methods can now be created.
...
Do not forget to dealloc variables.
- (void) dealloc { [bpLabel release]; [bpTextField release]; [super dealloc]; }
Finish the file with the keyword @end.
@end
The complete methods' file.
// // BapProgViewController.m // #import "BadProgViewController.h" @implementation BadProgViewController @synthesize bpLabel; @synthesize bpTextField; ... - (void) dealloc { [bpLabel release]; [bpTextField release]; [super dealloc]; } @end
Comments
Aidelinig (not verified)
Friday, July 1, 2011 - 10:48am
Permalink
very instructive
Anonymous (not verified)
Saturday, November 3, 2012 - 9:21am
Permalink
<p>Nice Implementation</p>
Nice Implementation
Add new comment