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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:27:11+00:00 2026-06-11T06:27:11+00:00

Im trying to add a UILabel programaticly (ive done it with IB and it

  • 0

Im trying to add a UILabel programaticly (ive done it with IB and it works). But I cant find out why it doesnt show up.. I’ve added a button programaticly that works just fine. I want the button to update the label with a random quote. Whats wrong?

.h-file:

@interface SecondViewController : UIViewController
{
    NSArray *citatDatabas;

}

@property (weak, nonatomic) IBOutlet UIButton *helloButton;
@property (weak, nonatomic) IBOutlet UIButton *citatKnapp;
@property (weak, nonatomic) IBOutlet UILabel *label1;

- (void)helloButtonPressed;
- (IBAction)citatKnappPressed:(id)sender;

@end

implementation:

@implementation SecondViewController
@synthesize helloButton, citatKnapp, label1;

- (void)loadView {
    [super loadView]; 
citatDatabas = [NSArray arrayWithObjects:
                    [NSString stringWithFormat:@"%@", @"People ask me, would you rather be feared or loved, um easy, I want people to be afriad of how much they love me - Michael Scott" ],
                    [NSString stringWithFormat:@"%@", @"You miss 100% of all the shoots you dont take - Wayne Greatsky - Michael Scott" ],
                    [NSString stringWithFormat:@"%@", @"DONT PANIC - hitchhiker's guide to the galaxy" ],
                    [NSString stringWithFormat:@"%@", @"Give someone a mask and they'll show their true face - Oscar Wilde" ],
                    [NSString stringWithFormat:@"%@", @"Given enough time, hydrogen starts to wonder where it came from, and where it is going" ],
                    [NSString stringWithFormat:@"%@", @"You have just begun reading the sentence you just finished reading" ],
                    nil];



    self.citatKnapp = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.citatKnapp.frame = CGRectMake(98, 162, 124, 37);
    [self.citatKnapp setTitle:@"Tryck för citat" forState:UIControlStateNormal];
    [self.citatKnapp addTarget:self action:@selector(citatKnappPressed:)     forControlEvents:UIControlEventTouchUpInside];

    self.citatKnapp.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

    [self.view addSubview:self.citatKnapp];

    self.label1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 71, 200, 83)];

    self.label1.frame = CGRectMake(20, 71, 200, 83);
    self.label1.text = @"hej";
    self.label1.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.label1];


}

- (IBAction)citatKnappPressed:(id)sender{

    self.label1.text = [citatDatabas objectAtIndex:
                  (random() % [citatDatabas count])];
}

@end
  • 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-11T06:27:13+00:00Added an answer on June 11, 2026 at 6:27 am

    Your label is getting released, use @property (strong, nonatomic) IBOutlet UILabel *label1;

    if you put a break point on any line after you alloc label1 you will see that label1 is nil

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

Sidebar

Related Questions

I'm trying to add a UILabel to my UIScrollView , but it doesn't show
I'm trying to add a label to my toolbar. Button works great, however when
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a blank sample app for a rails tutorial to GitHub, but
I am trying to add a UILabel anagrammatically like below - (void)viewDidLoad { [super
Trying to add a 'class' html attribute, but I think the keyword 'class' is
Trying to add a button to the right side of the toolbar of the
I am stumped trying to add a localized label to a custom button. I
I am trying to add a UILabel in UIWindow of AppDelegate from a UIViewController.
I'm trying to add some UI elements like UIProgressView , UILabel , UIButton and

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.