views:

1096

answers:

1

The UIKit reference says UIView is a superclass of UIWindow, but despite of this parentage, a UIWindow actually manages UIViews. This sounds so unusual to me.

Does anyone know what the significants of this are in terms of software design?

Many thanks.

EDIT:
I read the related paragraph in the iPhone programming guide. Yet I couldn't see why they do the reverse: let UIWindow be the parent of UIView. There must have been some thing that forced Apple to design the class hierarchy this way.

+1  A: 

from http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html

One thing that experienced Mac OS X developers may find unusual about the UIWindow class is its inheritance. In Mac OS X, the parent class of NSWindow is NSResponder. In iPhone OS, the parent class of UIWindow is UIView. Thus, in iPhone OS, a window is also a view object. Despite its parentage, you typically treat windows in iPhone OS the same as you would in Mac OS X. That is, you typically do not manipulate the view-related properties of a UIWindow object directly.

EDIT:

the UIView is something generic (provides common methods you use to create all types of views and access their properties. ) while UIWindow is more concrete (class defines objects that manage and coordinate the windows an application displays on the screen.)

I know is a little vague and I think only apple would know the exact reason for this hierarchy.

http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html#//apple_ref/occ/cl/UIWindow

The UIWindow class defines objects (known as windows ) that manage and coordinate the windows an application displays on the screen. The two principal functions of a window are to provide an area for displaying its views and to distribute events to the views.

and http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/cl/UIView

The UIView class provides common methods you use to create all types of views and access their properties. For example, unless a subclass has its own designated initializer, you use the initWithFrame: method to create a view. The frame property specifies the origin and size of a view in superview coordinates. The origin of the coordinate system for all views is in the upper-left corner.

UIView objects are arranged within an UIWindow object, in a nested hierarchy of subviews. Parent objects in the view hierarchy are called superviews, and children are called subviews. A view object claims a rectangular region of its enclosing superview, is responsible for all drawing within that region, and is eligible to receive events occurring in it as well. Sibling views are able to overlap without any issues, allowing complex view placement.

vaquito