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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:10:40+00:00 2026-06-16T16:10:40+00:00

I have a custom UIView (MyView) object that gets loaded from a xib file.

  • 0

I have a custom UIView (MyView) object that gets loaded from a xib file. In the MyView.m I have a method that gets called in initWithCoder that does some initialization. This works for the most part, but I was trying to set the text in some IBOutlet label properties here, and it wasn’t working, I realized because the properties were not initialized at this point.

I tried setting the text of the outlets in the drawRect method, and it does work. But I think I read that implementing drawRect if you don’t need to can cause some performance hits. My question is, where would the best place to set text of my IBOutlet label properties? (What I’m actually doing is setting it to localized versions of what’s in the xib. I know about localized xib files, but I want to set the text in code.)


Here is some code. Here is how I initialize the view in my view controller:

NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView"
                                                     owner:self
                                                   options:nil];
_myView = [nibContents objectAtIndex:0];

Here is the initWithCoder method in MyView.m

- (id)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self localizeLabels];
    }
    return self;
}

And here is the localizeLabels method:

- (void)localizeLabels
{
    self.powerPlant.text = NSLocalizedString(@"POWERPLANTBREAKDOWN_HEADERCOLUMN1", nil);
    self.output.text = NSLocalizedString(@"POWERPLANTBREAKDOWN_HEADERCOLUMN2", nil);
    self.capacity.text = NSLocalizedString(@"POWERPLANTBREAKDOWN_HEADERCOLUMN3", nil);
}

I have checked that these methods do get called using breakpoints, and that the properties are nil in the localizeLabels method.

  • 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-16T16:10:41+00:00Added an answer on June 16, 2026 at 4:10 pm

    UPDATED:
    Your MyView.m class should be like this in the start.

    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
            NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView"
                                                             owner:self
                                                           options:nil];
            UIView *_myView = [nibContents objectAtIndex:0];
            [self addSubview: _myView];
            [self localizeLabels];
        }
        return self;
    }
    
    - (id)initWithCoder:(NSCoder *)aDecoder {
        self = [super initWithCoder:aDecoder];
        if (self) {
            // Initialization code
            [self localizeLabels];
        }
        return self;
    }
    

    and in your viewcontroller. you need to initialize your MyView like this.

    MyView _view = [[MyView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [self.view addSubview:_view];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom UIView that has a xib file as well as .h and
I have a UIView that gets loaded with several custom NSObjects (graphShape). Each graphShape
I have a custom UIView class called MyView that I use together with a
I have a custom UIView that draws an image in the draw rect method.
I have a custom UIView. So myView class extend UIView. In initWithFrame:(CGRect)frame method I
I have a custom UIView that contains an interactive drawing that is drawn in
I have created a custom UIView (without .xib) for a finger paint application. Paint
I have a UIScrollView that contains a custom UIView. In my UIView I am
I have a custom view (inherited from UIView ) in my app. The custom
I have a custom UIView called TiledImage which has a single property named tiledImage

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.