Instance Property

subviews

The array of views embedded in the current view.

Declaration

@property(copy) NSArray<__kindof NSView *> *subviews;

Discussion

This array contains zero or more NSView objects that represent the views embedded in the current view’s content. The current view acts as the superview for each subview. The order of the subviews may be considered as being back-to-front, but this does not imply invalidation and drawing behavior.

When loading a view from a nib or storyboard file, the order of subviews is determined by the nib or storyboard file itself and usually corresponds to the order in which the views were added. Similarly, when adding subviews programmatically, the order is based on the order in which you added them.

When performing hit-test operations on a view, you should start at the last view in this array and work backwards.

Set this property to reorder the view’s existing subviews, add or remove subviews en masse, replace all of the view’s subviews with a new set of subviews, or remove all the view’s subviews. When you assign a valid, new array of subviews, the system performs required sorting and sends addSubview: and removeFromSuperview messages as necessary to leave the property with the requested new array.  Any member of the new array that isn't already a subview of the view is added.  Any member of the view's existing subviews array that isn't in the new array is removed.  Any views that are in both subviews and the new array are moved in the subviews array as needed, without being removed and re-added.

This property marks the affected view and window areas as needing display.

See Also

Managing the View Hierarchy

superview

The view that is the parent of the current view.

window

The view’s window object, if it is installed in a window.

- addSubview:

Adds a view to the view’s subviews so it’s displayed above its siblings.

- addSubview:positioned:relativeTo:

Inserts a view among the view’s subviews so it’s displayed immediately above or below another view.

- didAddSubview:

Overridden by subclasses to perform additional actions when subviews are added to the view.

- removeFromSuperview

Unlinks the view from its superview and its window, removes it from the responder chain, and invalidates its cursor rectangles.

- removeFromSuperviewWithoutNeedingDisplay

Unlinks the view from its superview and its window and removes it from the responder chain, but does not invalidate its cursor rectangles to cause redrawing.

- replaceSubview:with:

Replaces one of the view’s subviews with another view.

- isDescendantOf:

Returns YES if the view is a subview of a given view or if it’s identical to that view; otherwise, it returns NO.

opaqueAncestor

The view’s closest opaque ancestor, which might be the view itself.

- ancestorSharedWithView:

Returns the closest ancestor shared by the view and another specified view.

- sortSubviewsUsingFunction:context:

Orders the view's immediate subviews using the specified comparator function.

- viewDidMoveToSuperview

Informs the view that its superview has changed (possibly to nil).

- viewDidMoveToWindow

Informs the view that it has been added to a new view hierarchy.

- viewWillMoveToSuperview:

Informs the view that its superview is about to change to the specified superview (which may be nil).

- viewWillMoveToWindow:

Informs the view that it’s being added to the view hierarchy of the specified window object (which may be nil).

- willRemoveSubview:

Overridden by subclasses to perform additional actions before subviews are removed from the view.

enclosingMenuItem

The menu item containing the view or any of its superviews in the view hierarchy.