{"id":20154,"date":"2013-05-10T11:47:56","date_gmt":"2013-05-10T06:17:56","guid":{"rendered":"http:\/\/vskills.in\/certification\/tutorial\/?p=20154"},"modified":"2024-04-12T14:16:05","modified_gmt":"2024-04-12T08:46:05","slug":"view-hierarchy-and-switching","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/","title":{"rendered":"View Hierarchy and switching"},"content":{"rendered":"<h4><strong>View Hierarchy and switching<\/strong><\/h4>\n<h2>What Is a View Hierarchy?<\/h2>\n<p>In addition to being responsible for drawing and handling user events, a view instance can act as a container, enclosing other view instances. Those views are linked together creating a\u00a0<strong>view hierarchy<\/strong>. Unlike a class hierarchy, which defines the lineage of a class, the view hierarchy defines the layout of views relative to other views.<\/p>\n<p>The window instance maintains a reference to a single top-level view instance, call the\u00a0content view. The content view acts as the root of the visible view hierarchy in a window. The view instances enclosed within a view are called\u00a0<strong>subviews.<\/strong> The parent view that encloses a view is referred to as its\u00a0<strong>superview<\/strong>. While a view instance can have multiple subviews, it can have only one superview. In order for a view and its subviews to be visible to the user, the view must be inserted into a window&#8217;s view hierarchy.<\/p>\n<p><a ref=\"magnificPopup\" href=\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-29177\" src=\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png\" alt=\"view_hierarchy_enclose_1\" width=\"300\" height=\"101\" srcset=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png 300w, https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-1024x347.png 1024w, https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-624x211.png 624w, https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1.png 1127w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>This window&#8217;s view hierarchy has these parts.<\/p>\n<ol>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">The window is represented by an NSWindow instance.<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">The content view serves as the root of the window&#8217;s view hierarchy.<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">The content view contains a single subview, an instance of a custom class (that looks remarkably like an NSBox, but is not.).<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">The custom view instance that, in turn has two subviews, an NSButton instance, and an NSTextField instance.<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">The superview for both the button and text field is the NSBox object. The custom view container actually encloses the button and text field views.<\/span><\/li>\n<\/ol>\n<h2>Locating Views in the View Hierarchy<\/h2>\n<p>A rich selection of methods allows applications to access a view&#8217;s hierarchy. The\u00a0<code>superview<\/code>\u00a0method returns the view that contains the receiver, while the\u00a0<code>subviews<\/code>\u00a0method returns an array containing the view&#8217;s immediate descendants. If a view is the root of a view hierarchy, it returns\u00a0<code>nil<\/code>\u00a0when asked for its superview. Sending a view the\u00a0<code>window<\/code>\u00a0message returns the window the view resides in, or\u00a0<code>nil<\/code>\u00a0if the view is not currently in a window&#8217;s view hierarchy.<\/p>\n<p><a ref=\"magnificPopup\" href=\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/contents_sub_super_views_2x-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-29178\" src=\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/contents_sub_super_views_2x-2-238x300.png\" alt=\"contents_sub_super_views_2x 2\" width=\"238\" height=\"300\" srcset=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/contents_sub_super_views_2x-2-238x300.png 238w, https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/contents_sub_super_views_2x-2.png 572w\" sizes=\"auto, (max-width: 238px) 100vw, 238px\" \/><\/a><\/p>\n<p>Other methods allow you to inspect relationships among views:\u00a0<code>isDescendantOf:<\/code>\u00a0confirms the containment of the receiver;\u00a0<code>ancestorSharedWithView:<\/code>\u00a0finds the common container containing the receiver and the view instance specified as the parameter. For example, assuming a view hierarchy as shown in\u00a0Figure 3-2, sending<code>viewC<\/code>\u00a0a\u00a0<code>isDescendentOf:<\/code>\u00a0message with\u00a0<code>contentView<\/code>\u00a0as the parameter returns\u00a0<code>YES<\/code>. Sending\u00a0<code>viewB<\/code>\u00a0the<code>ancestorSharedWithView:<\/code>\u00a0message, passing\u00a0<code>viewC<\/code>\u00a0as the parameter, returns\u00a0<code>viewA<\/code>.<\/p>\n<p>The\u00a0<code>opaqueAncestor<\/code>\u00a0method returns the closest parent view that\u2019s guaranteed to draw every pixel in the receiver\u2019s frame (possibly the receiver itself).<\/p>\n<div class=\"apply\">\n<h3>Apply for iPhone Apps Certification Now!!<\/h3>\n<p><a href=\"http:\/\/www.vskills.in\/certification\/Certified-iPhone-Apps-Developer\" target=\"_blank\" rel=\"noopener\">http:\/\/www.vskills.in\/certification\/Certified-iPhone-Apps-Developer<\/a><\/p>\n<h4><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/iphone-apps-developer\/\" target=\"_blank\" rel=\"noopener\"><strong>Back to Tutorial<\/strong><\/a><\/h4>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>View Hierarchy and switching What Is a View Hierarchy? In addition to being responsible for drawing and handling user events, a view instance can act as a container, enclosing other view instances. Those views are linked together creating a\u00a0view hierarchy. Unlike a class hierarchy, which defines the lineage of a class, the view hierarchy defines&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[3347],"tags":[4507,4506],"class_list":["post-20154","page","type-page","status-publish","hentry","category-iphone-apps","tag-view-hierarchy","tag-view-hierarchy-and-switching"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>View Hierarchy and switching - Tutorial<\/title>\n<meta name=\"description\" content=\"View Hierarchy and switching\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"View Hierarchy and switching - Tutorial\" \/>\n<meta property=\"og:description\" content=\"View Hierarchy and switching\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:46:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/\",\"name\":\"View Hierarchy and switching - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png\",\"datePublished\":\"2013-05-10T06:17:56+00:00\",\"dateModified\":\"2024-04-12T08:46:05+00:00\",\"description\":\"View Hierarchy and switching\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#primaryimage\",\"url\":\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png\",\"contentUrl\":\"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"View Hierarchy and switching\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"View Hierarchy and switching - Tutorial","description":"View Hierarchy and switching","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/","og_locale":"en_US","og_type":"article","og_title":"View Hierarchy and switching - Tutorial","og_description":"View Hierarchy and switching","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:46:05+00:00","og_image":[{"url":"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/","name":"View Hierarchy and switching - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#primaryimage"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#primaryimage"},"thumbnailUrl":"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png","datePublished":"2013-05-10T06:17:56+00:00","dateModified":"2024-04-12T08:46:05+00:00","description":"View Hierarchy and switching","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#primaryimage","url":"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png","contentUrl":"http:\/\/vskills.in\/certification\/tutorial\/wp-content\/uploads\/2013\/05\/view_hierarchy_enclose_1-300x101.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/view-hierarchy-and-switching\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"View Hierarchy and switching"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/20154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=20154"}],"version-history":[{"count":6,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/20154\/revisions"}],"predecessor-version":[{"id":127082,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/20154\/revisions\/127082"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=20154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=20154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=20154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}