Re: Regarding MVC design pattern
Re: Regarding MVC design pattern
- Subject: Re: Regarding MVC design pattern
- From: Joanna Carter <email@hidden>
- Date: Wed, 19 May 2010 11:31:08 +0100
Hi Guys
Can I just suggest something more?
> @interface Controller : NSObject {
> IBOutlet UIButton *beginButton;
> IBOutlet UIButton *endButton;
> IBOutlet UILabel *nameLabel;
> IBOutlet UILabel *numberLabel;
> MyModel *myModel;
> }
>
> @property (nonatomic, retain) IBOutlet MyModel *myModel;
>
> /* some methods defined here as well */
> @end
From what I have read, and from good object-oriented practice, it would be better to use Objective-C 2.0 properties for all your outlets. iVars really should be @private, if you are using them, but don't forget that properties will synthesize, not only the accessors, but the ivars as well.
@interface Controller : NSObject
{
}
@property IBOutlet UIButton *beginButton;
@property IBOutlet UIButton *endButton;
@property IBOutlet UILabel *nameLabel;
@property IBOutlet UILabel *numberLabel;
@property MyModel *myModel;
/* some methods defined here as well */
@end
@implementation Controller
@synthesize beginButton;
@synthesize endButton;
@synthesize nameLabel;
@synthesize numberLabel;
@synthesize myModel;
@end
Any outlets for controls (top level objects) in the Nib should be released in the dealloc method only for OS X apps but not for iPhone apps. Setting the properties to nil will ensure that the synthesized setter will be called, which releases the previous contents of the synthesized ivar before setting it to nil.
- (void) dealloc
{
beginButton = nil;
endButton = nil;
nameLabel = nil;
numberLabel = nil;
myModel = nil;
[super dealloc];
}
Joanna
--
Joanna Carter
Carter Consulting
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden