Skip to content

Instantly share code, notes, and snippets.

@florieger
Created August 5, 2011 12:00
Show Gist options
  • Save florieger/1127386 to your computer and use it in GitHub Desktop.
Save florieger/1127386 to your computer and use it in GitHub Desktop.
View Controller Lifecycle Management [Xib Version] [MRC]
#pragma mark -
#pragma mark Controller Lifecycle
// Called once the view controller is initialized in your code
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Initialize iVars that live and die with your controller
_myList = [[NSMutableArray alloc] initWithCapacity:5];
}
return self;
}
// Called once the view controller is initialized in a xib file
- (id)initWithCoder:(NSCoder *)decoder
{
self = [super initWithCoder:decoder];
if(self){
// Initialize iVars that live and die with your controller
_myList= [[NSMutableArray alloc] initWithCapacity:5];
}
return self;
}
// Called once the controller is released
- (void)dealloc
{
// Release all iVars
[_myList release];
_myList = nil;
[_urlString release];
_urlString = nil;
// Release all IBOutlets
self.textView = nil;
self.textField = nil;
// Clean up superclass
[super dealloc];
}
#pragma mark -
#pragma mark View Lifecycle
// Called multiple times whenever the view loads.
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize iVars that life and die with your view
_urlString = @"www.appcron.com";
}
// Called on unload and memory warnings
- (void)viewDidUnload
{
[super viewDidUnload];
// Release all iVars that can be recreated by viewDidLoad
[_urlString release];
_urlString = nil;
// Release all IBOutlets
self.textView = nil;
self.textField = nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment