{"id":1480,"date":"2016-02-05T19:30:06","date_gmt":"2016-02-05T14:00:06","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=1480"},"modified":"2023-01-20T18:55:59","modified_gmt":"2023-01-20T13:25:59","slug":"view-controller-life-cycle-in-ios","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/","title":{"rendered":"View Controller Life Cycle in iOS"},"content":{"rendered":"<p><b>UIViewController<\/b><span style=\"font-weight: 400;\">&#8211; A view controller manages a set of views and makes your app\u2019s user interface. It coordinates with model objects and other controller objects. Basically, it plays a combine role for both view objects and controller objects. Each view controller shows it\u2019s own views to display the app content. The views are automatically loaded when the view property of view controller is accessed in the app.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">iOS provides several in built view controller classes for supporting standard user interfaces. These classes are UITableViewController, UINavigationController, UITabBarController etc.<\/span><\/p>\n<p><b>View Management-<\/b><span style=\"font-weight: 400;\"> A view controller uses the following methods to manage its views-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>loadView<\/b><span style=\"font-weight: 400;\">&#8211; You should never call this method manually. It is automatically called when its view property is accessed. It loads or creates a view and assigns it to the view property. Override this method in order to create view controller\u2019s default view manually. If you use Interface Builder to create view controller\u2019s views, you must not override this method. <\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\"><b>viewDidLoad<\/b><span style=\"font-weight: 400;\">&#8211; It is automatically called \u00a0when the view controller loaded completely in the memory. Override this method to perform additional initialization on views that were loaded from nib files and other tasks. E.g.-<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Instance variable initialization<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">XML parsing<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Network request<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Database access<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Heavy object allocation<\/span><\/li>\n<\/ol>\n<p><b>Event Management to Views-<\/b><span style=\"font-weight: 400;\"> A view controller uses the following methods to manage events to its views-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>viewWillAppear<\/b><span style=\"font-weight: 400;\">&#8211; It is called when the view controller\u2019s view is about to be added to the view hierarchy. Override this method to perform custom tasks associated with displaying the view. E.g.-<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Update navigation bar style<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Update status bar style<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Update screen data<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Orientation handling<\/span><\/li>\n<\/ol>\n<ul>\n<li style=\"font-weight: 400;\"><b>viewDidAppear<\/b><span style=\"font-weight: 400;\">&#8211; It is called when the view controller\u2019s view was added to the view hierarchy. Override this method to perform additional tasks associated with displaying the view. E.g.-<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Start UI animation<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Display loader view<\/span><\/li>\n<\/ol>\n<ul>\n<li style=\"font-weight: 400;\"><b>viewWillDisappear<\/b><span style=\"font-weight: 400;\">&#8211; It is called when the view controller\u2019s view is about to be removed from the view hierarchy. Override this method to perform following tasks-<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Commit editing changes<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Hide keyboard<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Revert changes that were made in viewWillAppear method<\/span><\/li>\n<\/ol>\n<ul>\n<li style=\"font-weight: 400;\"><b>viewDidDisappear<\/b><span style=\"font-weight: 400;\">&#8211; It is called when the view controller\u2019s view was removed from the view hierarchy. \u00a0Override this method to perform additional tasks associated with dismissing or hiding the view. E.g.-<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Remove cache data<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Stop services related to view like audio, bonjour service.<\/span><\/li>\n<\/ol>\n<p><b>Memory Management-<\/b><span style=\"font-weight: 400;\"> A view controller use this method to manage memory to its views-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>didReceiveMemoryWarning<\/b><span style=\"font-weight: 400;\">&#8211; It is called automatically when the system determines that the amount of available memory is low. Override this method to release any additional memory that is not essential. E.g.-<\/span><\/li>\n<\/ul>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Remove cache<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Release instance variables<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Release system resources like user\u2019s contacts database<\/span><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>UIViewController&#8211; A view controller manages a set of views and makes your app\u2019s user interface. It coordinates with model objects and other controller objects. Basically, it plays a combine role for both view objects and controller objects. Each view controller shows it\u2019s own views to display the app content. The views are automatically loaded when [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1996,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,71,8],"tags":[],"class_list":["post-1480","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-mobile","category-mobile-architecture-and-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>View Controller Life Cycle in iOS - InnovationM - Blog<\/title>\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.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"View Controller Life Cycle in iOS - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"UIViewController&#8211; A view controller manages a set of views and makes your app\u2019s user interface. It coordinates with model objects and other controller objects. Basically, it plays a combine role for both view objects and controller objects. Each view controller shows it\u2019s own views to display the app content. The views are automatically loaded when [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-05T14:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-20T13:25:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/02\/viewLifeController.png\" \/>\n\t<meta property=\"og:image:width\" content=\"700\" \/>\n\t<meta property=\"og:image:height\" content=\"700\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"View Controller Life Cycle in iOS\",\"datePublished\":\"2016-02-05T14:00:06+00:00\",\"dateModified\":\"2023-01-20T13:25:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/\"},\"wordCount\":467,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/viewLifeController.png\",\"articleSection\":[\"iOS\",\"Mobile\",\"Mobile Architecture and Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/\",\"name\":\"View Controller Life Cycle in iOS - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/viewLifeController.png\",\"datePublished\":\"2016-02-05T14:00:06+00:00\",\"dateModified\":\"2023-01-20T13:25:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/viewLifeController.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/02\\\/viewLifeController.png\",\"width\":700,\"height\":700},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/view-controller-life-cycle-in-ios\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"View Controller Life Cycle in iOS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"View Controller Life Cycle in iOS - InnovationM - Blog","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.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/","og_locale":"en_US","og_type":"article","og_title":"View Controller Life Cycle in iOS - InnovationM - Blog","og_description":"UIViewController&#8211; A view controller manages a set of views and makes your app\u2019s user interface. It coordinates with model objects and other controller objects. Basically, it plays a combine role for both view objects and controller objects. Each view controller shows it\u2019s own views to display the app content. The views are automatically loaded when [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/","og_site_name":"InnovationM - Blog","article_published_time":"2016-02-05T14:00:06+00:00","article_modified_time":"2023-01-20T13:25:59+00:00","og_image":[{"width":700,"height":700,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/02\/viewLifeController.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"View Controller Life Cycle in iOS","datePublished":"2016-02-05T14:00:06+00:00","dateModified":"2023-01-20T13:25:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/"},"wordCount":467,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/02\/viewLifeController.png","articleSection":["iOS","Mobile","Mobile Architecture and Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/","url":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/","name":"View Controller Life Cycle in iOS - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/02\/viewLifeController.png","datePublished":"2016-02-05T14:00:06+00:00","dateModified":"2023-01-20T13:25:59+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/02\/viewLifeController.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2016\/02\/viewLifeController.png","width":700,"height":700},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/view-controller-life-cycle-in-ios\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"View Controller Life Cycle in iOS"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/1480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=1480"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/1480\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/1996"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=1480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=1480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=1480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}