Monday, 12 May 2014

View controller and View delegate method (what and why)

1) loadView- Only called when view controller is created and only when done programitcally. Bounds are incorrect (normally empty) at this point.

2) viewDidLoad - Only called when view controller is created. Bounds are incorrect (normally empty) at this point.

3) viewWillAppear - Called whenever the view is presented on screen 

4 )viewWillLayoutSubviews - This is the first method where we have the correct bounds for the device and is called whenever the view controller is changing the display of the view (like device orientation, view loaded) or the UIView is marked as needing a layout

5) layoutSubviews - This method is called on the UIView rather than the UIViewController. It has the correct bounds. Great place to change layout.

6)viewDidLayoutSubviews - Called after layoutSubviews is called on UIView. Changes made in layoutSubviews can be animated, further changes made in this method can cancel the animations.


7) viewDidAppear - Called once the view has appeared. It has the correct bounds but changes called here can happen after an animation has occurred and cause a slight jump.

Sunday, 11 May 2014

Memory related question and Answer

1) Copy 
 =>It creates a new object and when new object is created retain count will be 1.
 =>Copy will copy the data present in the memory location and will assign it to the variable so in the case of copy you are first copying the data from a location assign it to the variable which increases the retain count.
=>Copy works on value only 
=>Copying an object, however you do it, should create another object with duplicate values. Think of this as a clone. You do NOT share the clone with whomever passed it to you.

2 )Retain
=> It is done on the created object, and it just increase the reference count of an object.
=>Retain copies the reference (address) and increases the retain count and you have to take care of releasing that object.
=> Increases the retainCount of the receiver. An object is removed from memory - deadlocked, when retainCount is 0.
=>Retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you.

3) Release
   =>Relese  decreases the reference on an object
4)Dreain
 =>Drain is used in place of release on ONLY for NSAutoreleasePool objects due to some arcana related to the Objective C garbage collection

5) Dealloc
    =>Dealloc is called by the system once the retainCount of an object hits 0. It is where you clean up various things your object has (like a deconstructor or finalizer). You should NEVER call it directly, except for calling [super dealloc] at the end of your dealloc routines.