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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:53:57+00:00 2026-05-25T05:53:57+00:00

Ugh, having some trouble here… I have 4 display labels in Interface Builder set

  • 0

Ugh, having some trouble here…

I have 4 display labels in Interface Builder set up as IBOutlets in the view controller.

I’ve set them up with these names
label1, label2, label3, label4

I’m want to change the label text for a randomly selected label

I’m trying this…

In the header file I declare as a property:

@property (nonatomic retain) UILabel *myLabel;

And then in my implementation file I synthesize and I’m trying

myLabel = [UILabel valueForKey: [NSString stringWithFormat:@"label%d", randomInt]];

myLabel.text = @"bleh!";

The myLabel = [UILabel … line is causing to crash. Any help? Thanks!

  • 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-25T05:53:58+00:00Added an answer on May 25, 2026 at 5:53 am

    You have the right idea, but you should pass valueForKey: to self, not UILabel, assuming its self that owns these properties.

    myLabel = [self valueForKey:[NSString stringWithFormat:@"label%d", randomInt]];
    

    As a side note, this is probably better done with an IBOutletCollection. In Xcode 4, select all of the labels and drag them to the header file. This will generate an IBOutletCollection NSArray containing all the outlets. You can then pick a random index from that array. It is usually unfortunate that IBOutletCollection stores its outlets in a non-deterministic order, but for your case it should be fine.

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

Sidebar

Related Questions

Ugh - not sure why I'm having so much trouble with this. Writing a
This is my first experience with javascript, and... Well... Ugh. Here's what's happening: function
I'm having trouble selecting the input value from this html: <li class=t-item> <div class=t-mid>
UGH. Hi. I have a form. I'd like to know how/if I could submit
Ugh! Any ideas? Have a form which tracks user activity for given time intervals.
I'm using old fashioned ASP.NET validation (ugh) for a checkout process. I have a
Here's the full setup for what I'm trying to do: We have an ActiveX
I have looked at some of the DICOM standard and the Wikipedia page (and
I have a set of classes with static methods. Example member of class set:
Ugh, you might think... Another syntax question, here let me google that for you

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.