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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:23:47+00:00 2026-05-20T09:23:47+00:00

I have a UIView subclass that I’d like to instantiate from a NIB file.

  • 0

I have a UIView subclass that I’d like to instantiate from a NIB file. I’ve been using this method to do it:

UINib *nib = [UINib nibWithNibName:@"SSNodeToolsView" bundle:[NSBundle mainBundle]];
self = [[[nib instantiateWithOwner:self options:nil] objectAtIndex:0] retain];

…and indeed this creates the object correctly and links everything up. However, the object instantly loses access to its delegate. The delegate is declared in the usual way:

id delegate
@property (nonatomic, assign) id delegate
@synthesize delegate

…and so on. However when the object loads from its nib the delegate instantly becomes null and ignores any attempt to assign values to it. Oddly this doesn’t cause a crash. Can anyone tell me why this is? I’d prefer to use the nib-loading method since these elements of my app are likely to be redesigned quite frequently and it would be easiest to do that using a nib.

-Ash

  • 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-20T09:23:47+00:00Added an answer on May 20, 2026 at 9:23 am

    Edit: moving the key point up to the top. You cannot simultaneously create an object and set it to file’s owner all in the same nib. The File’s Owner needs to be an already existing and initialized object with nil outlet ivars in order for the nib loading to hook up to the owner’s outlets properly.

    Is the delegate object also in the nib? If nothing retains it (your property is ‘assign’) it may just go away at the next autorelease pool drain. Is the delegate an outlet in your nib? “nil” values in outlets after loading a nib is usually a sign that the outlets are not connected correctly. Also, it appears that you’re instantiating the nib with an owner object (self) that is not yet initialized? If so, your outlets may not be connected correctly because outlets are only connected if the corresponding value in the owner object is nil. You should have a fully initialized owner object before using it as an owner in loading a nib.

    Here’s the “load this object from nib” initialization code I use in one of my projects:

    - (id)initWithFrame:(CGRect)frame 
    {
        self = [super initWithFrame:frame];
        if (self) 
        {
            // Initialization code.
            //
            [[NSBundle mainBundle] loadNibNamed:@"ScoreView" owner:self options:nil];
            [self addSubview:self.view];
        }
        return self;
    }
    
    - (void) awakeFromNib
    {
        [super awakeFromNib];
    
        [[NSBundle mainBundle] loadNibNamed:@"ScoreView" owner:self options:nil];
        [self addSubview:self.view];
    }
    

    Using nibs has a built-in level of indirection that you can’t avoid. You can’t create an object and simultaneously use it as File’s Owner — the owner must already exist and be initialized (with nil outlets) at nib loading time.

    Using the above code I can create my object either from code or place it directly into other nib files — a reusable UIView component.

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

Sidebar

Related Questions

I have a UIView subclass ( CustomView for purposes of this question) that has
I have a UIView subclass that draws a simple rectangle with this code: -
I have a UIView subclass that draws a curved line within it's frame (using
I have a problem with a UIView-subclass object that I am rotating using Core
I have a UIView subclass that I'm drawing a PDF onto (using a CATiledLayer).
I have a UIView subclass called ToolbarView that sort of acts like a floating
I have a UIView subclass that draws itself when -drawRect: is called. It only
I want to have a UIView subclass that has a border image, but I
So I have a Subclass of UIView that is suppose to detect touches. The
I have a UIView subclass that overrides UIResponder's touchesMoved: message. I've noticed that when

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.