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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:53:28+00:00 2026-06-18T12:53:28+00:00

Check out the following code: @property (weak, nonatomic) UILabel *l112; @property (weak, nonatomic) UILabel

  • 0

Check out the following code:

@property (weak, nonatomic) UILabel *l112;
@property (weak, nonatomic) UILabel *l212:
@property (weak, nonatomic) UILabel *l312:

((RBScorecardVC *)self.presentingViewController).l112.text = @"Hello"
((RBScorecardVC *)self.presentingViewController).l212.text = @"Hello"
((RBScorecardVC *)self.presentingViewController).l312.text = @"Hello"

Notice how I’m setting all the text of my labels to “Hello”. There must be a more efficient way of doing this. I am hoping I can somehow access the names of the UIlabels (l112, 1212, etc) to do so. Does this make sense? In my actual app, I’m not really setting everything to “Hello” but instead the the text is the result of a calculation. Also, in my actual app I have more than 3 labels to set (there are 50+) Here is my actual code using a repetitive if statement to access each UILabel sparately:

-(IBAction) submitScore: (id)sender
{
self.stringID = ((RBScorecardVC *)self.presentingViewController).self.giveString;

if (self.stringID isEqualToString:@"l112")
{ ((RBScorecardVC *)self.presentingViewController).l112.text = [[NSString alloc]initWithFormat:@"%d", self.accumulator];} //l112 is the name of my UILabel
else if (self.stringID is EqualToString:@"l212")
{ ((RBScorecardVC *)self.presentingViewController).l212.text = [[NSString alloc]initWithFormat:@"%d", self.accumulator];} //l212 is the name of my UILabel
}

I am wanting to be able to do it more efficiently like this:

-(IBAction) submitScore: (id)sender
 self.stringID = ((RBScorecardVC *)self.presentingViewController).self.giveString;

 ((RBScorecardVC *)self.presentingViewController).[UILabel withTitle:@"%@",stringID].text = [[NSString alloc]initWithFormat:@"%d", self.accumulator];}

Notice my [UILabel withTitle: @”%@”, stringID] part used within dot notation. I know this doesn’t work but I am wondering how I can write this correctly so stringID can be used to access the name of UILabel I need?

  • 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-18T12:53:30+00:00Added an answer on June 18, 2026 at 12:53 pm

    The other answers here deal with properties on objects. In this case you’re trying to access the objects themselves. When you start asking yourself a question like this, you should just store all of the objects (in this case, labels), in an array property instead of individual properties for each label. Instead of thinking about/referencing labels as named variables like l112, think of them as indexes in the array:

    UILabel *theLabelINeed = [self.myArray objectAtIndex:2];
    [theLabelINeed callWhateverMethodINeedTo];

    Or shorter, if you’re coming from a python/ruby background and this is more readable for you:

    [self.myArray[2] callWhateverMethodINeedTo];

    And if you need to quickly access every label in the array, you can use fast enumeration in a for-loop:

    for (UILabel *currLabel in self.myArray) {
        [currLabel callWhateverMethodINeedTo];
    }
    

    You could also use an NSDictionary instead, which lets you assign “keys” or names to objects.

    NSDictionary *dict {"l112": label1, "l113": label2}; // or some other dictionary creation method, maybe a mutable dictionary or whatever.
    UILabel *myLabel = [dict objectForKey:@"l112"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
Check out the following code (written just for fun) namespace N { template<typename T>
Check out the following code: private void Foo(object bar) { Type type = bar.GetType();
check out the following test: http://binks.knobbits.org/webgl/texture3.html It's a simple test of cube textures. It
Please check out the following func and its output void main() { Distance d1;
I am trying to check the following and all throw an out of bounds
I have the following code snippet <s:iterator status=stat value=masterAccountList> <tr> <td><s:property value=name/></td> <td><s:property value=status/></td>
Could anyone please explain to me why the following line of code prints out
I write the following code for some test, and the output is out of
I use the following code to get my View out of my controller: CollectionItemView

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.