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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:19:33+00:00 2026-05-29T08:19:33+00:00

I wonder how to add UI elements programatically to existing nib files. If I

  • 0

I wonder how to add UI elements programatically to existing nib files.

If I create a view programatically in loadView method and I add code like the following, the label displays correctly.

self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0,2,150,100)];

[self.view addView:lbl];

But how to add the label to an existing nib file?

  • 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-29T08:19:34+00:00Added an answer on May 29, 2026 at 8:19 am

    As Paul.s pointed out, you need to perform your custom code in viewDidLoad method.

    From Apple documentation.

    This method is called after the view controller has loaded its
    associated views into memory. This method is called regardless of
    whether the views were stored in a nib file or created
    programmatically in the loadView method. This method is most commonly
    used to perform additional initialization steps on views that are
    loaded from nib files.

    So, in your controller you could do this:

    - (void)viewDidLoad
    {
       [super viewDidLoad];
    
       // your other views here
    
       // call addSubview method on self.view
    }
    

    Why do you do this? Because here you are sure that view has loaded in memory and outlets has been set correctly.

    On the contrary, about loadView method

    If you override this method in order to create your views manually,
    you should do so and assign the root view of your hierarchy to the
    view property. (The views you create should be unique instances and
    should not be shared with any other view controller object.) Your
    custom implementation of this method should not call super.

    An example could be:

    - (void)loadView
    {
        CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
        UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
        contentView.backgroundColor = [UIColor whiteColor];
    
        self.view = contentView; 
    
        // call addSubview method on self.view
    }
    

    I suggest you to read View Controller Programming Guide for iOS.

    Hope it helps.

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

Sidebar

Related Questions

I just wonder how to add annotation in matlab plot? Here is my code:
I wonder if theres a way to add a html code to the tinymce
I have a LinearLayout view that already contains several elements. I want to add
new to vba, and wonder how to address elements within a range. I add
When answering another question I started to wonder how I could Add new properties
I wonder if someone can help me. I'm trying to add a reference to
wonder whether someone can help me with the following one... I have a struct
I wonder if it is better add an element by opening file, search 'good
i wonder why in the following example, trying to detach an element ( li
I wonder how I can add mysqldump to my MAMP environment. I googled a

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.