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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:05:55+00:00 2026-05-24T00:05:55+00:00

In this following code I intend to programmatically add two labels in each row

  • 0

In this following code I intend to programmatically add two labels in each row in a scrollable view. “label” gets added in the view with no problem but “infoLabel” I only see the last row.
Has spent hours trying to figure out.
Thanks for any help.

- (void)refreshList
{
    // remove all the labels from the GUI
    for (UILabel *label in scrollView.subviews)
        [label removeFromSuperview];
    RootModel *rm = [RootModel sharedModel];

    float labelOffset = LABEL_SPACING; // reset the spacing
    UILabel *infoLabel = [[UILabel alloc] init ];

    // repopulate the scroll view with Labels
    for (UILabel *label in labels)
    {
        NSLog(@"%@", label.text);
        CGRect labelFrame = label.frame; // fetch the frame of label

        labelFrame.origin.x = LEFT_LABEL_SPACING; // set the x-coordinate
        labelFrame.origin.y = labelOffset; // set the y-coordinate
        labelFrame.size.width = scrollView.frame.size.width/3;
        labelFrame.size.height = LABEL_HEIGHT; // set the height of Label
        label.frame = labelFrame; // assign the new frame to Label
        [scrollView addSubview:label]; // add Label as a subview

        CGRect infolabelFrame = infoLabel.frame; // fetch the frame of label

        infolabelFrame.origin.x = 10; // set the x-coordinate
        infolabelFrame.origin.y = labelOffset; // set the y-coordinate
        infolabelFrame.size.width = scrollView.frame.size.width/3;
        infolabelFrame.size.height = LABEL_HEIGHT; // set the height of Label
        infoLabel.frame = infolabelFrame; // assign the new frame to Label

        NSString *key = label.text;
        NSLog(@"%@", key);
        infoLabel.text = [rm.rLevels valueForKey:key];
        NSLog(@"%@    %@", infoLabel.text, key);

        infoLabel.frame = infolabelFrame; // fetch the frame of label
        [infoLabels addObject:infoLabel];
        [scrollView addSubview:infoLabel]; // add Label as a subview

        // increase the offset so the next button is added further down
        labelOffset += LABEL_HEIGHT + LABEL_SPACING;
    } // end for
} // end refreshList
  • 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-24T00:05:55+00:00Added an answer on May 24, 2026 at 12:05 am

    You are creating a single instance of infoLabel and resetting its frame on each iteration of the loop. If you intend to have multiple labels, you will have to allocate and initialize a label on each iteration on the loop. Make sure you relinquish the ownership of the label you are allocating after you add it as a subview.

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

Sidebar

Related Questions

This following code gets this compile error: " invalid types 'int[int]' for array subscript
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
Did I not get enough sleep or what? This following code var frame=document.getElementById(viewer); frame.width=100;
The following code is throwing the error this.element is null. However, the wid_cont is
The following code fails in 'Evaluate' with: This expression was expected to have type
The following code in javascript gives me the error this.callback is not a function
The following code doesn't work! 'this' in in the context when i access it
In the following code: public class A { public A():this(null){} public A(string b){/*code here*/}
The following code rearranges elements by the attribute amount. How can I alter this
In the following code, g++ gives this error : 1.cpp: In member function void

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.