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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:51:40+00:00 2026-06-14T21:51:40+00:00

I need an example of how to instantiate a custom view from a nib

  • 0

I need an example of how to instantiate a custom view from a nib file. i wrapped my head around several stackoverflow posts but i didn’t get it. Maybe i only need a hint how to do it.

what I want to do is – creating a custom view with interface builder. it should be a template so that i can instantiate it multiple times to add it to multiple view controllers.

So far I have created my custom view xib file called MyIssueView.xib. Which consists in fact just of the main view and some labels.

And I created a Subclass of UIView which is called IssueView with the Outlets for my labels in the MyIssueView.xib.

How do I now hook up the outlets with the IB? And how can I instantiate the IssueView from any ViewController?

Would be glad for an example!
Cheers.

UPDATE:

I now have

IssueView.xib
IssueView.h (UIView Subclass)
IssueView.m

My IssueView.h:

#import <UIKit/UIKit.h>

@interface IssueView : UIView

@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UILabel *label3;
@property (weak, nonatomic) IBOutlet UILabel *label4;

@end

My IssueView.m:

#import "IssueView.h"

@implementation IssueView
@end

My ViewController.m:

#import "AllIssuesViewController1.h"
#import "IssueView.h"
#import "UIView+NibLoading.h"

@interface AllIssuesViewController1 ()

@end

@implementation AllIssuesViewController1


- (void) loadView
{

}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _issueView = [IssueView loadInstanceFromNib];
}

It gives me an error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x8292580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.'
  • 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-14T21:51:42+00:00Added an answer on June 14, 2026 at 9:51 pm

    I have a category that extends UIView called UIView+NibLoading.

    In it is this code…

    #import "UIView+NibLoading.h"
    
    @implementation UIView (NibLoading)
    
    + (id)loadInstanceFromNib
    {
        UIView *result;
    
        NSArray* elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
    
        for (id anObject in elements) {
            if ([anObject isKindOfClass:[self class]]) {
                result = anObject;
                break;
            }
        }
    
        return result;
    }
    
    @end
    

    Then when I want to instantiate a UIView subclass from a nib I just import the category and I can run…

    self.issueView = [IssueView loadInstanceFromNib];\
    

    You need to connect the labels like this…

    enter image description here

    If you connecting the labels to “File’s Owner” then you’ll need to remove those connections.

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

Sidebar

Related Questions

Aloha, I have a custom control that I need to instantiate from within a
I need an example of the shortest path of a directed cyclic graph from
I need an example pom file to create a jar file for my spring
For example I need to grab from http://gmail.com/ the number of free storage: Over
I need to instantiate generic variable like Class>. For example, Class<? extends List<String>> =
need a simple example of how to call ApplicationPinServices BeginVerifyPin and EndVerifyPin methods from
I am using the SWFUpload from http://www.anedix.com/data/file/news/realname/swfupload-php-example-v1_4.zip and want to integrate this into my
I need and example of how to integrate Maven, Spring MVC, LessCss and Wro4j
i need an example of the shortest path of directed graph cycle bye one
For Example: I need to develop a Small Inventory program for nearby Super Market

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.