Tuesday 22 March 2011

UIView and UIViewController

In this post we will have a close look at the difference between UIView and UIViewController.

UIView and UIViewController both are classes and are of equally important but both the classes have their own specialty. First we will have a discussion of UIView and then UIViewController to understand the concepts of both the classes.

UIView: UIView is a class which holds the other views, in iPhone each and every control is refereed as a view. You can add a view inside another view and to hold all these views you need a container and your UIView class acts as container where you can add another views like the buttons,labels, switch, slider etc because of this the UIView can have the parent and child relationship between them know as the subviews and the parent view doing the embedding is called as the superview. Every UIView is related with UIViewController which manages the UIView.

Some Important instance method of UIView class

addSubview: It takes a parameter of the UIView instance (label,buttons, etc) which is to be added.

drawRect: This method is used when you want to draw something in the view like circle, rectange etc.

didAddSubView: Informs whether a subview was added.

removeFromSuperView: It removes a view from the parent view and from the responder chain.

UIViewController: UIViewController class is used to control the UIView instance (object) and the view which are present in the UIView (buttons,labels,table). The ViewController manages the modal view, device rotation, memory management etc, Subclasses such as UINavigationController and UITabbarController provide additional behavior for managing complex hierarchies of view controllers and views.The UIViewController has a view property with the help of which you can refer to the view which it controls, now this view can have another view like the button,label,table etc.

Some important instance method of the UIViewController class:

loadView: In this method you add the controls to the self view but before that you make a call to the super class loadview method so that the view that you are going to add in the self view are being added properly. This method is called when the view property of the viewController is accessed and you must use the loadView method only when you are adding views programmatically (without using Interface builder).

viewDidLoad: This method always gets called when we want do some manipulations with the views after they are loaded in the memory. This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method.

viewDidAppear: Notifies the view controller that its view was added to a window.

viewDidDisappear: Notifies the view controller that its view was dismissed, covered, or otherwise hidden from view.

viewWillAppear: Notifies the view controller that its view is about to be become visible.

viewDidUnload: It is called when the when the controller’s view is released from the memory.

BitCode hopes that this post has helped you in clearing your concepts regarding the view and view controllers. You can post your queries at bitcode.pune@gmail.com for any technical assistance.


  1. very helpful thank........

  2. I have bееn exploгіng for а bit foг any high-quality aгtіcles
    or blog posts in thіѕ κind оf
    houѕe . Exploring in Yаhoo I ultimаtеly stumbled uρon thіs website.

    Ѕtudying thіѕ information So i am glad to exрreѕs thаt I've an incredibly just right uncanny feeling I came upon exactly what I needed. I such a lot unquestionably will make sure to don?t overlook this website and give it a look regularly.

    My site - [source]

  3. Increasіngly peoрle today are adоpting thіs teсhnіque which they're obtaining extremely easy to practice.

    Feel free to visit my webpage; faq.arbuz.ru

  4. Usually every cartridge will give the equivalent of one particular pack of
    tobacco cigarettes. Starter packs are packages that contain everything that you need to have to begin successfully smoking your electronic cigarette.

    Several men and women start off smoking in their teens and are addicted by
    the time they are adults. The battery makes it possible for a light to seem on the finish of the device
    (the color depends on the brand you pick), and it
    also makes it possible for the vaporizer to develop the smoke impact.
    Outstanding client service!

    Feel free to surf to my web blog - Www.Prnewswire.Com