Created
October 14, 2011 15:56
-
-
Save florieger/1287487 to your computer and use it in GitHub Desktop.
View Controller Lifecycle Management [Xibless Version] [MRC]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - | |
#pragma mark Controller Lifecycle | |
// Called once the view controller is initialized in your code | |
- (id)init | |
{ | |
self = [super init]; | |
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 Views you've retained | |
self.view = nil; | |
[_myLabel release]; | |
_myLabel = nil; | |
// Clean up superclass | |
[super dealloc]; | |
} | |
#pragma mark - | |
#pragma mark View Lifecycle | |
// Called multiple times whenever the view loads to recreate the view without a XIB file. | |
- (void)loadView | |
{ | |
// Important, don't call [super loadView]. | |
// See Apple's View Controller Programming Guide (Custom View Controllers) for details. | |
UIView* baseView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; | |
baseView.backgroundColor = [UIColor redColor]; | |
self.view = baseView; | |
[baseView release]; | |
// Top View | |
_myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 250, 20)]; | |
_myLabel.text = @"AppCron"; | |
[self.view addSubview:_myLabel]; | |
} | |
// 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 Views that can be recreated by loadView | |
self.view = nil; | |
[_myLabel release]; | |
_myLabel = nil; | |
// Release all iVars that can be recreated by viewDidLoad | |
[_urlString release]; | |
_urlString = nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment