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 6642275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:54:41+00:00 2026-05-25T23:54:41+00:00

I ask this question because it appears that viewDidLoad gets called before the main

  • 0

I ask this question because it appears that viewDidLoad gets called before the main block of the initializer does and the class variables I’m initializing in the initializer are turning up nil in viewDidLoad. For your reference, I’m doing this entire viewcontroller programmatically and I’ve created a custom initializer so I can take in various parameters to be used in my viewcontroller. My custom initializer calls UIViewControllers designated initializer of course.

Basically, I’m curious about what is the proper design pattern for sending in parameters to a UIViewController? I’ve read other threads about this and haven’t really gotten a definitive answer. Should I just skip the initializer and set the properties manually (from outside the class)? That seems kind of bleh, I’d really like to send in some parameters and am curious how others go about doing 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-05-25T23:54:41+00:00Added an answer on May 25, 2026 at 11:54 pm

    The reason viewDidLoad is called before initialization completes, is probably because you call the view method in the initializer. For example:

    - (id)init
    {
        if ((self = [super init])) {
            _thing = 123;
            _other = self.view.frame.size.width / 2;
        }
    
        return self;
    }
    

    viewDidLoad is called when the view loads. And the view loads as soon as you call the view method (or access the view property, if you prefer). So you should avoid referencing the view in init.

    To answer your question, I prefer to create an init method for my view controllers.

    - (id)initWithThing:(MyThing *)thing thang:(MyThang *)thang
    {
        if ((self = [super init])) {
            _thing = [thing retain];
            _thang = [thang retain];
            // ...
        }
    
        return self;
    }
    

    You can also use properties to set extra variables after initing. Personally I prefer to do this with optional properties only, though, and put required properties in the init method. That way I can’t init the view controller with an invalid state.

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

Sidebar

Related Questions

I ask this question because i learned that in programming and designing, you must
I ask this question because I'm not able to test it at the moment.
This question is mostly academic. I ask out of curiosity, not because this poses
I am not even sure how to ask this question. I want something that
I ask this question because I find the the community contributions to the various
I almost didn't dare to ask this question because it looks trivial but after
I ask this question because I've implemented a javascript solution to nested inlines (it
I am hesitated to ask this question because it looks weird. But anyway. Just
I'm hesitant to ask this question because of the vagueness of the situation, but
This is the second time I ask this question because in my first 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.