Monday, July 25, 2011

iPhone/iPad Technical Interview Question(FAQ) with answers(Part 2)

Q11. What is atomic and nonatomic property attribute? 
Both are same unless we use our setter and getter methods.
If we create our own setter and getter method, then atomic is useful in thread processing, but it is slow.
Nonatomic does not give guarantee on thread processing but it is fast.

Q12. What is the life cycle of view controller?
A.  Press here....
Q13. Difference between viewDidLoad, viewWillAppear, viewDidAppear and viewLoad?
  • ViewDidLoad - The viewDidLoad method is only called when the view is first loaded from the Nib file. If the view was already loaded and you push the view again it will not fire again. viewDidLoad is things you have to do once.Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms.
  • ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).
when you are loading things from a server, you also have to think about latency. If you pack all of your network communication into viewDidLoad or viewWillAppear, they will be executed before the user gets to see the view - possibly resulting a short freeze of your app. It may be good idea to first show the user an unpopulated view with an activity indicator of some sort. When you are done with your networking, which may take a second or two (or may even fail - who knows?), you can populate the view with your data. Good examples on how this could be done can be seen in various twitter clients. For example, when you view the author detail page in Twitterrific, the view only says "Loading..." until the network queries have completed.
  • ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.
  • ViewLoad: loadView is the method in UIViewController that will actually load up the view and assign it to the "view" property. This is also the location that a subclass of UIViewController would override if you wanted to programatically set up the "view" property.
          I've found that often when I add init code to loadView, I end up with an infinite stack trace
          Don't read self.view in -loadView. Only set it, don't get it.
          The self.view property accessor calls -loadView if the view isn't currently loaded. There's your infinite recursion.

All The Best :)

Next(Part 3)….