Wednesday, 1 May 2013

View Controller Lifecycle

View Controllers are the controllers of your MVC. They have a Lifecycle. (They are created, do some task and they die.)

There are certain methods in view controller which notify you of what's going on. View controller can be created by alloc init by 99% of time MVCs are instantiated out of a story board.

Put set up codes for your view in viewDidLoad:

-(void) viewDidLoad{

 [super viewDidLoad];


}

But remember geometry is not set in viewDidLoad. You can do it in viewWillAppear:


-(void)viewWillAppear: (BOOL)animated;


Your view will only load once, but it may appear and disappear few times.
If your things you are displaying is changing while your app is off screen, you should add the code to viewWillAppear.


didRecievedMemoryWarning

In low memory situation, didRecievedMemoryWarning is called. It is very rare to happen, but if it happens you can set the pointer of the object that causes it to nil and reload your data. Keep in mind to use caching in your program where it makes sense.

awakeFromNib 

This message is sent to every single object that comes out of the story board. It happens before the MVC is loaded and before all the outlets are set.
written by: infinitywebseo 

No comments:

Post a Comment