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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:27:41+00:00 2026-05-16T18:27:41+00:00

I used the code to try set the label text but its not working.

  • 0

I used the code to try set the label text but its not working. I though maybe I forgot to connect the outlet with the label, or i connected the wrong outlet but they were ok once I checked them. Made sure the xib was saved.

.m

@synthesize nameLabel;
@synthesize infoLabel;

-(void) updateUI
{
nameLabel.text = @"test1";
infoLabel.text = @"test2";
}

.h

UILabel * nameLabel;
UILabel * infoLabel;
@property(nonatomic, retain) IBOutlet UILabel *nameLabel;
@property(nonatomic, retain) IBOutlet UILabel *infoLabel;

Thats pretty much all the code used in the veiw controller related to these labels. Is there something i am missing that might explain this strangeness?

The default text i have in the labels ‘name’ & ‘info’ is what is showing.

This is the code that gets called prior to updateUI being called

browseDeckViewController.m

-(void) viewDidLoad 
{
    cardOnTopOfDeck = 0; 
    cardSecondFromTopOfDeck=1;
    deck = [[Deck alloc] init];
    [deck loadDeckData];
    Card *mySecondCard = [[Card alloc] init];
    mySecondCard = [deck.deckArray objectAtIndex:cardSecondFromTopOfDeck];
    secondCard = [[CardViewController alloc] initWithNibName:@"CardViewController"               
    bundle:[NSBundle mainBundle] numberOfStats:kNumStats];
    [secondCard setCard:mySecondCard];
    CGRect frame = secondCard.view.frame;
    frame.origin.x = (320-frame.size.width)/2;
    frame.origin.y = 10;
    secondCard.view.frame = frame;  
    [self.view addSubview:secondCard.view];


    topCard = [[CardViewController alloc] initWithNibName:@"CardViewController"    
    bundle:[NSBundle mainBundle] numberOfStats:kNumStats];
    Card *myTopCard = [[Card alloc] init];
    myTopCard = [deck.deckArray objectAtIndex:cardOnTopOfDeck];
    [topCard setCard:myTopCard];
    frame = topCard.view.frame;
    frame.origin.x = (320-frame.size.width)/2;
    frame.origin.y = 10;
    topCard.view.frame = frame;
    [self.view addSubview:topCard.view];
}

CardViewController.m

    -(void) setCard:(Card *)newCard 
    {
    [card release];
    card = [newCard retain];
    [self updateUI];
    }

   -(void) updateUI
   {
    NSLog(@"updateUI");
    nameLabel.text = @"test1";
    infoLabel.text = @"test2";
   }
  • 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-16T18:27:41+00:00Added an answer on May 16, 2026 at 6:27 pm

    Your CardViewController is created and then you immediately try to set the text of a UILabel in that controller’s view. The problem is, the view isn’t loaded yet. At the time updateUI is called, viewDidLoad: has not yet been called for the CardViewController, which means nameLabel and infoLabel are nil.

    You have to force the CardViewController‘s view to load from the NIB before trying to access any of the outlets. a simple [self view]; would suffice. For example:

    -(void) updateUI {
         NSLog(@"nameLabel's value: %@",nameLabel); //nil here
         [self view];
         NSLog(@"nameLabel's value after loading view: %@",nameLabel); //Now it's loaded
         nameLabel.text = @"test1";
         infoLabel.text = @"test2";
    }
    

    EDIT:

    Another solution would be to move the call to updateUI to after addSubview:

    myTopCard = [deck.deckArray objectAtIndex:cardOnTopOfDeck];
    [self.view addSubview:topCard.view];
    [topCard setCard:myTopCard];
    frame = topCard.view.frame;
    frame.origin.x = (320-frame.size.width)/2;
    frame.origin.y = 10;
    topCard.view.frame = frame;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have never used Try-catch in my code before, but now I need to
I want to set file length to zero. i used following code try {
I have used this code to send mails but I am not getting any
I have used this code to store Object to a file: try{ FileOutputStream saveFile=new
I have used the code below to read rfid tag values. try { if
This code used to return my local ip address as 192.xxx.x.xxx but now it
This code used to work but doesnt any more. i used a breakpoint, and
This code used to work. Then, maybe I changed something, somewhere (or if I
The below code simply is not working on my Android Galaxy Nexus running v4.0.2
i have the following code used to serialize a label's content. When i press

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.