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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:06:39+00:00 2026-06-15T02:06:39+00:00

Let me first say that I’ve searched Google and, although many have similar issues,

  • 0

Let me first say that I’ve searched Google and, although many have similar issues, I haven’t seen anything with the following bizarre behavior and remedy.

I’ve created a UIViewController and associated nib with several IBOutlets. On trying to consume this nib from another class, I discovered that after instantiating it with initWithNibName:bundle:, the IBOutlets are still nil.

I confirmed that they are correctly wired up, and yes, they are being synthesized, but still nothing. While investigating further, I changed the initWithNibName method as follows:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        UIView *view = self.view;
        NSArray *subviews = self.view.subviews;
        NSLog(@"Loaded view containing %d subviews.", [subviews count]);

    }
    return self;
}

Unbelievably, the addition of the three lines here, creating throwaway variables and logging, makes the IBOutlets wire up properly and work from the outside.

I have cleaned and rebuilt and restarted my machine, but still, if I remove these lines, it stops working. I am really baffled here and concerned that I have some kind of voodoo working that’s going to break the moment I ship. Any ideas on what could be happening?

  • 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-15T02:06:40+00:00Added an answer on June 15, 2026 at 2:06 am

    You misunderstand what initWithNibName:bundle: does, and when a UIViewController loads its nib.

    The initWithNibName:bundle: method records the name of the nib to be loaded. It does not immediately load the nib.

    The -[UIViewController view] method loads the nib on demand, by sending [self loadView] if necessary. The implementation of -[UIViewController view] is basically this:

    - (UIView *)view {
        if (_view == nil) {
            [self loadView];
            [self viewDidLoad];
        }
        return _view;
    }
    

    So if you call self.view in your initWithNibName:bundle: override, that will cause the view controller to load its nib.

    However, it’s generally inappropriate to call self.view from initWithNibName:bundle:. A view controller should be able to exist without its view hierarchy.

    For example, suppose a user is running your app and navigates through several view controllers, which you implement by pushing the view controllers onto a navigation controller. Then the user switches to another app for a while. Now the system is running low on memory, so it kills background apps – including your app.

    When the user launches your app again, your app (if it’s well done) should try to restore the user’s state. That means reloading the navigation controller with the stack of push view controllers. But only the top view controller’s view is visible on screen. It would be a waste of time, memory, and battery to reload the views for all of the hidden view controllers immediately. That’s why each view controller loads its nib on demand.

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

Sidebar

Related Questions

First, let me just say that I have searched for information on this topic;
First of, let me just say that I know similar questions have been asked
Let's say I have a form that collects a first name and a last
Let's say that I have 2 lines like this. Some Label: First element Second
First let me say that I have been working on this issue for about
First, let me say that I have read other responses on this, and I
I have a web app that has to do something every, let's say first
Let me first say that I have quite a lot of Java experience, but
Let's say that I have two accordion tabs. The first one loads hundreds of
I have a question, but let me first say that this is being performed

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.