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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:34:13+00:00 2026-06-09T16:34:13+00:00

I have a UI that was made using code only pretty much: everything (UIlabels,

  • 0

I have a UI that was made using code only pretty much: everything (UIlabels, etc) are initialized within viewdidload of the view controller.

.h

@interface homeViewController : UIViewController {

    //IBOutlet UILabel *lbl; // not using an outlet anyway...
    UILabel *lbl; 
}

@property(nonatomic,retain) UILabel *lbl;



@end

.m

@interface homeViewController ()

@end

@implementation homeViewController

@synthesize lbl;



-(void)updateLabel {


    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

    double temptemp2 = [ud doubleForKey:@"somekey"];

    lbl.text = [NSString stringWithFormat:@"%f", temptemp2]; 

    [ud synchronize];


}

then in the viewdidload i just call [self updateLabel]; and the label does not get updated. however, if I put the same code that’s inside updateLabel method into view did load, the code works.

the UIlabel is being initialized (alloc init) ahead of the [self updateLabel]; inside of view did load .

How should I initialize the label object properly if I do not want to do it using interface builder? so that it is accessible form other methods inside of the same view controller?

  • 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-09T16:34:14+00:00Added an answer on June 9, 2026 at 4:34 pm

    You have created a @property on your view controller for the label, however when you create the label you are assigning it to a local variable instead of the property. Because of this you are unable to reference it later from your other method when you want to assign the value.

    In your viewDidLoad, assign the UILabel object you have created to the property like this:

    self.lbl = lbl;
    

    Then in your updateLabel method:

    self.lbl.text = [NSString stringWithFormat:@"%f", temptemp2]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using jQuery and rails. I have made a simple form that
I made a custom handler that derives from MvcHandler. I have my routes using
my question is that I have made multimap.Here is the partial code. if(binary_search(final.begin() ,
I'm fairly new to ggplot. I have made a bumpplot using code posted below.
I have a navigation that I made using CSS Sprites. The thing is I
Using Firebug I have found that the Dynatree plugin changes the following code: <li
I have a UIView that contains a drawing that I've made using CALayers added
I have a VERY simple C# Winforms project that I made using Visual Studio
I have this sql that is made by help of others. $sql = select
I have a website that I made and I am planning to redo it.

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.