开发者

iPhone. View architecture

开发者 https://www.devze.com 2022-12-30 08:46 出处:网络
Can a开发者_如何学JAVAnyone summarize the relationship between the following items? Content View

Can a开发者_如何学JAVAnyone 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消