views:

49

answers:

1

Can anyone summarize the relationship between the following items?

  1. Content View
  2. View Controller
  3. Nib
  4. the view, subclass of UIView
  5. Application delegate

I got very confused about these. Coz some people say the "content view" contains the "nib" while other people say "content view" and "nib" are not containing each other.

Many thanks!

+1  A: 

Oh man… that's not so easy. But I'll try.

  • Application is being launched from main().
  • Application delegate receives callbacks from Application during runloop. For example, when app finished launching or something else.
  • Usually application contains single instance of UIWindow, that is the root of all view hierarchy.
  • UIWindow can have UIViews, they can have UIViews by themselves. So, there's a hierarchy of UIViews (a tree)
  • Each view has controller, that gets user input and other events and controls UIView (for example, tells it to redraw itself because of user tap). Controller can be standard or custom, written by developer.
  • Content View is a normal view. Usually within a table cell. UITableViewCell instance has a property that is called contentView. It's a normal view and it can be any UIView subclass.

NIB is another story. You can create whole view hierarchy by yourself. But there is an alternative way: use Interface Builder. After creating views/subviews in the interface builder — you can save this hierarchy with all its properties as a single (serialized) file. And load it at once during application run.

NIB has three main objects. File Owner is an object, that you'll get when you send some message like

+ (BOOL)loadNibNamed:(NSString *)aNibName owner:(id)owner

Here owner will be filled with all properties of File Owner from the NIB.

First responder - first receives input. You can simply forget about it for now.

View — is the main view. Usually it is linked to a view property of File Owner.

It's a veeery short overview of all these things. You really have to read documentation to understand it better.

Alexander Babaev