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

  • SEARCH
  • Home
  • 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 8025237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:06:08+00:00 2026-06-04T23:06:08+00:00

For a controller that is pushed by a nav controller, if in its desired

  • 0

For a controller that is pushed by a nav controller, if in its desired init method you create the details of the pushed controller’s view, my understanding is that if the view is removed later because it is offscreen (due to low memory, for example), you may never see it again since the init is only called once when loading the view controller, and subsequent pushes may show nothing.

It would seem a better place for this view setup is in the viewDidLoad or viewWillAppear, that way it will be recreated correctly if the controller needs to build the view the next time it is pushed.

Yet I see tutorials that often put the pushed view controller’s view setup in its init method; how important is this?

  • 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-06-04T23:06:10+00:00Added an answer on June 4, 2026 at 11:06 pm

    View setup should be done in viewDidLoad (or in loadView if you’re not using a nib), for exactly the reason you’re describing. If you need to know the controller’s top-level view dimensions to set up the subviews, then do it in viewWillAppear:.

    Usually, a view controller that is popped is immediately deallocated; if the app needs to show the same view later, it creates a new view controller for it. So in that scenario, the app won’t show “nothing”.

    If the app pushes or presents another view controller on top of the first view controller, the first view controller’s view can be unloaded. If the app never pushes or presents a second view controller over the first view controller, the first view controller’s view can’t be unloaded until the controller is popped, at which time (in most apps) the controller is deallocated anyway. So in that case, setting up the view in init won’t cause trouble.

    But it’s still bad design to set up views in init. You might change your app later to push or present a second view controller, thus creating unexpected unsafe behavior.

    Also, it’s common to create a view controller, set properties on it, and then push it. If the properties affect the controller’s view hierarchy, then init is too early to set up the views.

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

Sidebar

Related Questions

I have pushed a view onto my nav controller that contains a UIWebView and
How should I pass a string to the view controller that gets pushed when
I have a Nav controller that starts at a table view. Each row pushes
the view controller that is pushed onto the stack cannot be an instance of
I have a view (viewB) that is pushed in using the navigation controller from
We have a controller that might be pushed from several places, so its back
I'm working on a view controller that can be presented modally or pushed into
I'm working on an app where different view controllers that get pushed and popped
I have a segue (called ToSettingsSegue ) that pushes a custom view controller (
Have a controller that is failing to create a post. When I create (try

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.