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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:35:52+00:00 2026-06-09T11:35:52+00:00

I am facing a problem with updating my labels.. it doesn’t remove the old

  • 0

I am facing a problem with updating my labels.. it doesn’t remove the old values so new values go on top of old ones.. any help with this will be appreciated..

timer = [NSTimer scheduledTimerWithTimeInterval:1
                                         target:self
                                       selector:@selector(updateLabels)
                                       userInfo:nil
                                        repeats:YES];

-(void) updateLabels{
    for (GraphView *graph in arr){
        // retrieve the graph values
        valLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * 200, 0, 90, 100)];
        valLabel.textColor = [UIColor whiteColor];
        valLabel.backgroundColor = [UIColor clearColor];
        valLabel.text = [NSString stringWithFormat:@"Value: %f", x];
        i++;
    }        
}
  • 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-09T11:35:54+00:00Added an answer on June 9, 2026 at 11:35 am

    If you set the text of your label you do not need to call setNeedsDisplay or clearContext etc.

    In your code, I do not know what are your variables i and x?

    The main problem is that you are creating and adding new labels on your view. When you call updateLabels method, may cause a Memory leak. Simply you have n times labels overlapped.

    You need to remove the labels before you create and add new labels or you can reuse which you already have. To reuse your labels you need to save them to an array and update texts.

    If you want to create new labels then you can do like this unless you have other labels in your view

    -(void) updateLabels{
    // remove all labels in your view   
    for (UIView *labelView in self.view.subviews) {
        if ([labelView isKindOfClass:[UILabel class]]) {
        [labelView removeFromSuperview];
    }
    
    for (GraphView *graph in arr){
        // retrieve the graph values
        valLabel = [[UILabel alloc] initWithFrame:CGRectMake(i * 200, 0, 90, 100)];
        valLabel.textColor = [UIColor whiteColor];
        valLabel.backgroundColor = [UIColor clearColor];
        valLabel.text = [NSString stringWithFormat:@"Value: %f", x];
        i++;
    }        
    }
    

    When you create new labels like this you need to add them to your view as subview

    [self.view addSubview: valLabel];
    

    if you have other labels in your view then you can save them in an array and remove just them

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

Sidebar

Related Questions

I am facing problem finding any solution for converting my PDF to HTMl/xml.This requirement
iam facing problem in passing array to view. this is my controller code.. function
i am facing problem with ipv6 validations and ipv4 validations in JavaScript please help
Im facing problem with poor performance of css prompting mechanism. Can I dissable this
i am facing problem with the return type for this function and not really
i am facing problem in jquery tool tip, when i am searching any image
I am facing problem when comparing 2 strings values using C:When tag I am
I am facing problem with sql query when I try to join this tree
This time I am facing problem while performing dual operation on UIImageView means 1)
Iam facing problem in understanding and converting a matlab code into opencv. I want

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.