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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:12:35+00:00 2026-06-01T08:12:35+00:00

i have a performance issue in my tableview my cellForRow looks like that: if

  • 0

i have a performance issue in my tableview

my cellForRow looks like that:

if (tableView == allMonthTable) {

        static NSString *cellIdentifier = @"cell";

        AllMonthCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell == nil) {
            cell = [[AllMonthCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] ;
        }
        Month *mo = [[dataHandler allMonth]objectAtIndex:indexPath.section];
        double budgetValue = mo.budget.doubleValue;
        [cell.budgetLabel setText:[NSString stringWithFormat:@"%.2f",budgetValue ]];
        double spentValue = mo.spent.doubleValue;
        [cell.spentLabel setText:[NSString stringWithFormat:@"%.2f",spentValue ]];
        if (spentValue > 0) {
            [cell.spentLabel setText:[NSString stringWithFormat:@"+%.2f",spentValue]];
            [cell.spentLabel setTextColor:[self greenColor]];    
        }
        else if (spentValue < 0){
            [cell.spentLabel setText:[NSString stringWithFormat:@"%.2f",spentValue]];
            [cell.spentLabel setTextColor:[self redColor]];      
        }
        double balanceValue = budgetValue+spentValue;
        [cell.balanceLabel setText:[NSString stringWithFormat:@"%.2f",balanceValue ]];
        if (balanceValue > 0) {
            [cell.balanceLabel setText:[NSString stringWithFormat:@"+%.2f",balanceValue]];
            [cell.balanceLabel setTextColor:[self greenColor]];    
        }
        else{
            [cell.balanceLabel setText:[NSString stringWithFormat:@"%.2f",balanceValue]];
            [cell.balanceLabel setTextColor:[self redColor]];      
        }
        double avgDayValue = mo.avgDay.doubleValue;
        [cell.avgDayLabel setText:[NSString stringWithFormat:@"%.2f",avgDayValue ]];

        if (avgDayValue > 0) {
            [cell.avgDayLabel setText:[NSString stringWithFormat:@"+%.2f",avgDayValue]];
        }
        int numberOfExpValue = mo.expenses.intValue;
        [cell.numberOfExpLabel setText:[NSString stringWithFormat:@"%d",numberOfExpValue ]];
        return cell;
    }
    return nil;
}

and my AllMonthCell.m files looks like that:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        UIFont *font = [UIFont fontWithName:@"Cochin" size:14.0];
        UIFont *fontBold = [UIFont fontWithName:@"Cochin-Bold" size:14.0];


        self.frame = CGRectMake(0, 0, 312, 100);

        UIView *top = [[UIView alloc]initWithFrame:CGRectMake(4, 0, 304, 1)];
        [top setBackgroundColor:[UIColor lightGrayColor]];

        UILabel *budgetStringLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 102, 16)];
        [budgetStringLabel setTextAlignment:UITextAlignmentLeft];
        [budgetStringLabel setFont:font];
        [budgetStringLabel setTextColor:[UIColor lightGrayColor]];
        [budgetStringLabel setText:@"Month Budget:"];
        [budgetStringLabel setBackgroundColor:[self grayColor]];

        UILabel *spentStringLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, 102, 16)];
        [spentStringLabel setTextAlignment:UITextAlignmentLeft];
        [spentStringLabel setFont:font];
        [spentStringLabel setTextColor:[UIColor lightGrayColor]];
        [spentStringLabel setText:@"Spent Money:"];
        [spentStringLabel setBackgroundColor:[self grayColor]];

        UIView *divide1 = [[UIView alloc]initWithFrame:CGRectMake(10, 50, 292, 1)];
        [divide1 setBackgroundColor:[UIColor lightGrayColor]];


        UILabel *balanceStringLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 55, 102, 16)];
        [balanceStringLabel setTextAlignment:UITextAlignmentLeft];
        [balanceStringLabel setFont:font];
        [balanceStringLabel setTextColor:[UIColor lightGrayColor]];
        [balanceStringLabel setText:@"Month Balance:"];
        [balanceStringLabel setBackgroundColor:[self grayColor]];

        UIView *divide2 = [[UIView alloc]initWithFrame:CGRectMake(10, 74, 292, 1)];
        UIView *divide3 = [[UIView alloc]initWithFrame:CGRectMake(10, 76, 292, 1)];
        [divide2 setBackgroundColor:[UIColor lightGrayColor]];
        [divide3 setBackgroundColor:[UIColor lightGrayColor]];


        UILabel *avgDayStringLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 94, 200, 16)];
        [avgDayStringLabel setTextAlignment:UITextAlignmentLeft];
        [avgDayStringLabel setFont:font];
        [avgDayStringLabel setTextColor:[UIColor lightGrayColor]];
        [avgDayStringLabel setText:@"Per Day:"];
        [avgDayStringLabel setBackgroundColor:[self grayColor]];

        UILabel *numberOfExpStringLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 114, 102, 16)];
        [numberOfExpStringLabel setTextAlignment:UITextAlignmentLeft];
        [numberOfExpStringLabel setFont:font];
        [numberOfExpStringLabel setTextColor:[UIColor lightGrayColor]];
        [numberOfExpStringLabel setText:@"Expenses Made:"];
        [numberOfExpStringLabel setBackgroundColor:[self grayColor]];

        [self addSubview:budgetStringLabel];
        [self addSubview:top];
        [self addSubview:spentStringLabel];
        [self addSubview:divide1];
        [self addSubview:balanceStringLabel];
        [self addSubview:divide2];
        [self addSubview:divide3];
        [self addSubview:numberOfExpStringLabel];
        [self addSubview:avgDayStringLabel];


        self.budgetLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 10, 102, 16)];
        [self.budgetLabel setTextAlignment:UITextAlignmentRight];
        [self.budgetLabel setFont:font];
        [self.budgetLabel setBackgroundColor:[self grayColor]];
        [self.budgetLabel setTextColor:[UIColor darkGrayColor]];



        self.spentLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 30, 102, 16)];
        [self.spentLabel setTextAlignment:UITextAlignmentRight];
        [self.spentLabel setFont:font];
        [self.spentLabel setBackgroundColor:[self grayColor]];
        [self.spentLabel setTextColor:[UIColor lightGrayColor]];



        self.balanceLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 55, 102, 16)];
        [self.balanceLabel setTextAlignment:UITextAlignmentRight];
        [self.balanceLabel setFont:fontBold];
        [self.balanceLabel setBackgroundColor:[self grayColor]];



        self.avgDayLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 94, 102, 16)];
        [self.avgDayLabel setFont:font];
        [self.avgDayLabel setBackgroundColor:[self grayColor]];
        [self.avgDayLabel setTextColor:[UIColor lightGrayColor]];
        [self.avgDayLabel setTextAlignment:UITextAlignmentRight];






        self.numberOfExpLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 114, 102, 16)];
        [self.numberOfExpLabel setTextAlignment:UITextAlignmentRight];
        [self.numberOfExpLabel setFont:font];
        [self.numberOfExpLabel setBackgroundColor:[self grayColor]];
        [self.numberOfExpLabel setTextColor:[UIColor lightGrayColor]];




        [self addSubview:self.budgetLabel];
        [self addSubview:self.spentLabel];
        [self addSubview:self.balanceLabel];
        [self addSubview:self.numberOfExpLabel];
        [self addSubview:self.avgDayLabel];


        [self setBackgroundColor:[self grayColor]];

    }
    return self;
}

here is a screenshot of time profiling while scrolling:

time profile

so i create reusable cells of the type AllMonthCell, and assign the values to them, is there a way to make it faster? i have pretty serious lags while scrolling the table..

a hint would be great 🙂

  • 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-01T08:12:36+00:00Added an answer on June 1, 2026 at 8:12 am

    You should reuse the cells

    Let me derive you a pattern

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellIdentifier = @"cell";
        UILabel *noExpense;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] autorelease];
            //Just the view alone should be created here no assigning of data here
            //let me add just one custom view for easy understanding
            noExpense = [[UILabel alloc]initWithFrame:CGRectMake(8, 20, 296, 16)];
           [noExpense setTextAlignment:UITextAlignmentCenter];
           [noExpense setFont:fontName];
           //[noExpense setText:@"No data available yet."];  Dont do this
           [noExpense setTextColor:[UIColor lightGrayColor]];
           [noExpense setBackgroundColor:tableView.backgroundColor];
           [noExpense setTag:100];  //Must set tag here
           [cell addSubview:noExpense];
        }
        else
        {
            noExpense = [cell viewWithTag:100];
            //You have to initialize your custom views which you created already.
            //Just the view alone should be assigned here no assigning of data here
        }
        //Load all the data into the views here
        [noExpense setText:@"Somedata which you have to set"];
        return cell;
    }
    

    To know more about tableview see the doc. Its the bible for understanding tableviews.

    http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7

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

Sidebar

Related Questions

Just like in this topic , I have a performance issue in dev mode
I have a performance issue regarding a quite simple query that run for more
I have a quite serious performance issue with the following statement that i can't
I have several performance issue in my website. I'm using asp.net mvc 2 and
I've got an performance issue in my application using a MSSQL DB. I have
I have just migrated to mysql 5.5.20 and I had a performance issue with
I have problem with my widget related to performance and memory: Issue : My
I have a jQueryMobile site/app where performance is an issue. I am reading a
I'm struggling with a performance issue for a copy feature that my application provides
we have some performance issue with a program, I traced tsql using sql server

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.