Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:19:45+00:00 2026-05-29T04:19:45+00:00

When the user switches to another program and then back again., the original program’s

  • 0

When the user switches to another program and then back again., the original program’s view will be replaced by a new view from another program. So when the user switches back to the original program, would viewDidLoad be called the second time ?

Am asking this because if this is the case, then the initialization code placed inside viewDidLoad would be executed every time the user switches the screen back and forth. And this could result in reseting views and loosing unfinished works of the user …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:19:46+00:00Added an answer on May 29, 2026 at 4:19 am

    Don’t do view controller initialisation in viewDidLoad. This is a common mistake.

    For stuff that should only happen once when the view controller is loaded, do it in the controller’s init method, like this:

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)bundleOrNil
    {
        if ((self = [super initWithNibName:nibNameOrNil bundle:bundleOrNil]))
        {
            //do your initialisation here
        }
        return self;
    }
    

    The initWithNibName:bundle: method is called before the view is loaded from the nib, and is only called once in the lifespan of the view controller.

    The controller’s view can be loaded and unloaded multiple times during the lifespan of the controller and viewDidLoad will be called every time. It may be unloaded whenever it’s not on screen, usually if memory is low.

    If you do set stuff up in viewDidLoad (e.g. adding subviews programmatically) you should always unset them again in viewDidUnload.

    Think of viewDidLoad and viewDidUnload as being like the init/dealloc for the view property of the view controller. For stuff that relates to the views, create and release it in those methods. For stuff that relates to the controller itself, create and release it in initWithNibName and dealloc.

    UPDATE: On iOS 6 and later, viewDidUnload is never called any more (unless the view is explicitly set to nil in the code), and so viewDidLoad will typically only be called once in the life of a view controller. This makes the advice above less critical, but it’s still best practice, and still necessary if you need to support iOS 5 and earlier.

    UPDATE 2: If you are loading your view controller from a Storyboard (which is now the recommended practice) instead of creating it programmatically then initWithNibName:bundle: will not be called. Use initWithCoder: or awakeFromNib to initialize your controller instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to run a method when a user switches to another tab or
CPU Switches from User mode to Kernel Mode : What exactly does it do?
Is there a winforms event that fires when the user switches from a form
I'm trying to detect when a user switches away from the current browser tab,
With iOS multitasking a running app's state is saved when the user starts another
I need to save data in distinct TabItem every time when user switches to
I'm adding a row to a UITableView section when the user switches the table
I need to know when a user refreshs the page and when he switches
I would like to create a button in my game for the user. The
I have an application that allows an admin user to switch into another user's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.