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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:20:41+00:00 2026-05-29T21:20:41+00:00

here is my problem: My UITableViewController lags when I scroll it. It has about

  • 0

here is my problem:
My UITableViewController lags when I scroll it. It has about 60 custom cells. However, on the simulator it works without any lags.
Here is my code:
CustomCell.m

#import "CustomCell.h"

@implementation CustomCell

@synthesize nameLabel,costLabel,giftPicture;

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


        nameLabel = [[UILabel alloc]init];
        nameLabel.textAlignment = UITextAlignmentLeft;
        nameLabel.textColor = [UIColor colorWithRed:25/256.0 green:98/256.0       blue:52/256.0 alpha:1.0];
        costLabel = [[UILabel alloc]init];
        costLabel.textAlignment = UITextAlignmentLeft;


        giftPicture = [[UIImageView alloc]init];

        [self.contentView addSubview:nameLabel];
        [self.contentView addSubview:costLabel];
        [self.contentView addSubview:giftPicture];

        costLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background4"]];
        nameLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background4"]];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];

    CGRect contentRect = self.contentView.bounds;
    CGFloat boundsX = contentRect.origin.x;
    CGRect frame;
    frame= CGRectMake(boundsX+10,10, 50, 50);
    giftPicture.frame = frame;

    frame= CGRectMake(boundsX+70 ,10, 350, 25);
    nameLabel.frame = frame;

    frame= CGRectMake(boundsX+70 ,40, 350, 18);
    costLabel.frame = frame;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

List.m

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [array1 count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithFrame:CGRectZero];
    }

    // Configure the cell...


    NSString *cellValue = [array1 objectAtIndex:indexPath.row];
    //cell.textLabel.text = cellValue; // загаловок клетки
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; // сделал чтобы клетка была со стрелочкой

    cell.nameLabel.text = cellValue;

    NSDictionary  *mainDictionary = [[NSDictionary alloc]init];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];
    if([currentLanguage isEqualToString:@"en"])
    {
        mainDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"animals" ofType:@"txt"]];
    }
    NSEnumerator *enumerator = [mainDictionary objectEnumerator];
    id returnValue;

    while ((returnValue = [enumerator nextObject]))
    {

        if([cell.nameLabel.text isEqualToString:[returnValue valueForKey:@"name"]] )
        {

            cell.animalPicture.image = [UIImage imageNamed:[returnValue valueForKey:@"icon"]];
            cell.costLabel.text = [NSString stringWithFormat:@"$%@ - $%@",[returnValue valueForKey:@"minAge"],[returnValue valueForKey:@"maxAge"]];

        }
    }
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 75;
}
@end

I tried to make custom cells empty (remove labels and images), just because of curious, but it didn’t change anything.
Could you tell me please, what I should check to fix these lags?
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-29T21:20:42+00:00Added an answer on May 29, 2026 at 9:20 pm

    Yeah thats just a TON of work to be doing for each table cell I think (also never never never trust the simulator for performance, it means nothing in relation to how things will behave on the device). You should try and use instruments to pinpoint exactly whats taking time but if I had to look at that I would say:

    NSDictionary  *mainDictionary = [[NSDictionary alloc]init];
    

    Just for starters this a) seems pointless because of this next line and b) looks like you are leaking this.

        mainDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"animals" ofType:@"txt"]];
    

    Loading this file in every time cannot be stellar for performance, you should bring this data in once to like your view controller instead of every time you fill out a cell.

    NSEnumerator *enumerator = [mainDictionary objectEnumerator];
    id returnValue;
    
    while ((returnValue = [enumerator nextObject]))
    {
    
        if([cell.nameLabel.text isEqualToString:[returnValue valueForKey:@"name"]] )
        {
    

    This whole chunk here, I would rework. This is to be blunt, using an NSDictionary wrong. A dictionary contains a Key and a Value, you shouldn’t have to scan through the whole thing yourself with an enumerator to find the value you want by doing string comparisons, you should be using something like

    [mainDictonary objectForKey:@"thingYouWant"];
    

    doing what you said is like 60 complete enumerations of the dictionary and string comparisons can’t be good for table performance and isn’t necessary.

    That would be the stuff I work check for performance first and then rework as needed, I’m willing to bet your performance issues are contained in those chunks.

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

Sidebar

Related Questions

What is the problem here? (Besides having redundant code). $.getJSON works as expected. However
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I'm trying to solve the problem here but I don't know why my code
hi all i have implemented code as shown in the below here problem is
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I have a problem here. My Zend_Forms do not render in view script. Via
I've got a problem here with an MSI deployment that I'm working on (using
Just a small SVN problem here. I setup my own SVN server Setting up
I'm facing a problem here, with HttpListener. When a request of the form http://user:password@example.com/
I have an interesting problem here I've been trying to solve for the last

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.