I noticed that I many of my IBOutlets were only being used to modify the view
from the viewDidLoad methods but which were not accessed later in my code.
These outlets exist so that I can keep consistent appearance settings in a
large number of nibs without actually editing each nib. As a simplified example
(typed into Mail, but should describe the pattern), consider the following.
----- begin old style -----
@interface Class : UIViewController
@property (nonatomic, retain) IBOutlet UILabel* label;
@end
@implementation Class
@synthesize label=myLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
self.label.textColor = kLabelTextColor;
self.label.text = NSLocalizedString(@"Blah blah blah", @"Label text");
}
- (void)viewDidUnload
{
self.label = nil;
[super viewDidUnload];
}
- (void)dealloc
{
[myLabel release];
[super dealloc];
}
@end
----- end old style -----
I have replaced this with the following:
----- begin new style -----
@interface Class : UIViewController
@property (nonatomic, assign) IBOutlet UILabel* label;
@end
@implementation Class
- (void)setLabel:(UILabel*)label
{
label.textColor = [UIColor lightGray];
label.text = NSLocalizedString(@"Blah blah blah", @"Label text");
}
- (UILabel*)label
{
NSAssert(NO, @"label is inaccessible");
return nil;
}
@end
----- end new style -----
The new style allows me to focus on non-trivial activities in viewDidLoad,
viewDidUnload, and dealloc (sometimes even eliminating those methods) and
reduces the number of things that need to be memory managed.
So the question: anyone see any problems with this?
Aaron_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]