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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:59:42+00:00 2026-05-23T22:59:42+00:00

I created a custom UIView subclass, and would prefer to not layout the UI

  • 0

I created a custom UIView subclass, and would prefer to not layout the UI in code in the UIView subclass. I’d like to use a xib for that. So what I did is the following.

I created a class “ShareView” which subclasses UIView. I created a XIB file with its file’s owner set to “ShareView”. Then I link some outlets I declared in my “ShareView.h”.

Next I have a ViewController, MainViewController, which adds the ShareView as a subview. whith this code:

NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"ShareView" owner:nil options:nil];
UIView *fv = [[arr objectAtIndex:0] retain];
fv.frame = CGRectMake(0, 0, 320, 407);
[self.view addSubview:fv];

But now I get NSUnknownKeyException errors on the outlets I declared in my ShareView.

The reason I did all this is because I want a UIView, with its own logic in a seperate XIB file. I read in several places that ViewControllers are only used to manage a full screen, i.e. not parts of a screen…
So what am I doing wrong? I want my logic for ShareView in a seperate class, so my MainController class doesn’t get bloated with logic from ShareView (which I think is an aption to solve this problem?)

  • 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-23T22:59:43+00:00Added an answer on May 23, 2026 at 10:59 pm

    ThomasM,

    We had similar ideas about encapsulating behavior inside a custom view (say, a slider with companion labels for min/max/current values, with value-changed events also handled by the control internally).

    In our current best-practice, we would design the ShareView in Interface Builder (ShareView.xib), as described by Eimantas in his answer. We then embed the ShareView to the view hierarchy in MainViewController.xib.

    I wrote up how we embed custom-view Nibs inside other Nibs in our iOS developer blog. The crux is overriding -awakeAfterUsingCoder: in your custom view, replacing the object loaded from MainViewController.xib with the one loaded from the “embedded” Nib (ShareView.xib).

    Something along these lines:

    // ShareView.m
    - (id) awakeAfterUsingCoder:(NSCoder*)aDecoder {
        BOOL theThingThatGotLoadedWasJustAPlaceholder = ([[self subviews] count] == 0);
        if (theThingThatGotLoadedWasJustAPlaceholder) {
            // load the embedded view from its Nib
            ShareView* theRealThing = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ShareView class]) owner:nil options:nil] objectAtIndex:0];
    
            // pass properties through
            theRealThing.frame = self.frame;
            theRealThing.autoresizingMask = self.autoresizingMask;
    
            [self release];
            self = [theRealThing retain];
        }
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom UIView that I would like to use on multiple
I have created a custom subclass of UIView for an interface element that I
I have created a subclass of UIView and I would like to have it
I've created a custom UIView, and inside that UIView, I add a UITableView like
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I created a custom ComboBox as follows: (note, code is not correct but you
I currently have a simple iPhone app that loads a custom subclass of UIView.
I've created a custom view that loads its content from a nib, like this:
I have created the following subclass to do some custom drawing: // DocumentIconView.h @interface
I have created a UIView subclass in order to implement a custom drawRect method.

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.