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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:36:09+00:00 2026-05-26T11:36:09+00:00

I have a UITableView which sometimes just stops responding when its been loaded. I

  • 0

I have a UITableView which sometimes just stops responding when its been loaded. I have no clue why this happens and I was wondering whether it could be the layouting of the cells which I do in cellForRowAtIndexPath, because my content is dynamic and therefore the layout of the subviews has to be adopted each time.

Is there a better approach to achieve what I want? Or is there anything else wrong with this?

Here is the code I wrote:

First the method which creates the custom cell and adds the different views to the content view:

- (UITableViewCell *)tableViewCellWithReuseIdentifier:(NSString *)identifier {


    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];


    UILabel *titleLbl, *amountLbl, *title2Lbl, *numberLbl, *mergeLbl, *typeLbl;


    UIColor *bgColor, *blackColor, *amountColor , *title2Color;
    UIColor *clearColor = [UIColor clearColor];


    bgColor = [UIColor clearColor];
    title2Color = [UIColor colorWithRed:0.1 green:0.1 blue:0.6 alpha:1];
    amountColor = [UIColor redColor];
    blackColor = [UIColor blackColor];

    //The number
    numberLbl = [[UILabel alloc] initWithFrame:CGRectZero];
    numberLbl.tag = kNumberLblTag;
    numberLbl.font = [UIFont systemFontOfSize:12];
    numberLbl.textAlignment = UITextAlignmentLeft;
    numberLbl.textColor = blackColor;
    numberLbl.backgroundColor = clearColor;
    numberLbl.numberOfLines = 0;
    [cell.contentView addSubview:numberLbl];
    [numberLbl release];

    amountLbl = [[UILabel alloc] initWithFrame:CGRectZero];
    amountLbl.tag = kamountLblTag;
    amountLbl.font = [UIFont systemFontOfSize:12];
    amountLbl.textAlignment = UITextAlignmentLeft;
    amountLbl.textColor = amountColor;
    amountLbl.backgroundColor = clearColor;
    amountLbl.numberOfLines = 0;
    [cell.contentView addSubview:amountLbl];
    [amountLbl release];


    mergeLbl = [[UILabel alloc] initWithFrame:CGRectZero] ;
    mergeLbl.tag = kMergeLblTag;
    mergeLbl.font = [UIFont systemFontOfSize:12];
    mergeLbl.textAlignment = UITextAlignmentLeft;
    mergeLbl.textColor = blackColor;
    mergeLbl.backgroundColor = clearColor;
    mergeLbl.numberOfLines = 0;
    [cell.contentView addSubview:mergeLbl];
    [mergeLbl release];


    typeLbl = [[UILabel alloc] initWithFrame:CGRectZero];
    typeLbl.tag = kTypeLblTag;
    typeLbl.font = [UIFont systemFontOfSize:12];
    typeLbl.textAlignment = UITextAlignmentLeft;
    typeLbl.textColor = blackColor;
    typeLbl.backgroundColor = clearColor;
    typeLbl.numberOfLines = 1;
    [cell.contentView addSubview:typeLbl];
    [typeLbl release];


    titleLbl = [[UILabel alloc] initWithFrame:CGRectZero];
    titleLbl.tag = kTitleLblTag;
    titleLbl.font = [UIFont systemFontOfSize:14];
    titleLbl.textAlignment = UITextAlignmentLeft;
    titleLbl.textColor = blackColor;
    titleLbl.backgroundColor = clearColor;
    titleLbl.numberOfLines = 0;
    [cell.contentView addSubview:titleLbl];
    [titleLbl release];


    title2Lbl = [[UILabel alloc] initWithFrame:CGRectZero];
    title2Lbl.tag = ktitle2LblTag;
    title2Lbl.font = [UIFont systemFontOfSize:12];
    title2Lbl.textAlignment = UITextAlignmentLeft;
    title2Lbl.textColor = title2Color;
    title2Lbl.backgroundColor = clearColor;    
    title2Lbl.numberOfLines = 0;
    [cell.contentView addSubview:title2Lbl];
    [title2Lbl release];


    UIView *bgView = [[UIView alloc]initWithFrame:CGRectZero];
    bgView.backgroundColor = bgColor;
    cell.backgroundView = bgView;
    [bgView release];


    NSLog(@"tableViewCellWithReuseIdentifier");

    return cell;

}

And here the method which resizes the subviews for each cell:

    // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {



    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];



    NSUInteger row = [indexPath row];
    NSUInteger section = [indexPath section];

    NSUInteger r = row+(section*100);

    if (cell == nil) {

        cell = [self tableViewCellWithReuseIdentifier: CellIdentifier];

    }

    UIColor *bgColor, *clearColor = [UIColor clearColor];





    //set the rePointer to the actual array 
    if (r < [results count]) {
        rePointer = results;
        //NSLog(@"results r: %i", r);
    }else {
        r = [indexPath row];
        rePointer = rejects;
        //NSLog(@"rejects r: %i", r);

    }



    NSString *noTxt = [[NSString alloc]initWithFormat:@"%i.", r+1];
    CGSize boundingSize = CGSizeMake(35, 100);
    UIFont *sysFont = [UIFont systemFontOfSize:12]; 
    CGSize requiredSize = [noTxt sizeWithFont:sysFont constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
    CGFloat requiredHeight = requiredSize.height;

    UILabel *numberLbl = (UILabel*)[cell viewWithTag:kNumberLblTag];
    numberLbl.frame = CGRectMake(5, 5, 35, requiredHeight);
    numberLbl.text = noTxt;





    NSMutableString *amountTxt = [[NSMutableString alloc]initWithString:@"amount: "];
    [amountTxt appendString:[NSString stringWithFormat:@"%@", [[rePointer objectAtIndex:r] objectForKey:@"amount"]]];


    boundingSize = CGSizeMake(35, 100);
    sysFont = [UIFont systemFontOfSize:12]; 
    requiredSize = [amountTxt sizeWithFont:sysFont constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
    requiredHeight = requiredSize.height;

    UILabel *amountLbl = (UILabel*)[cell viewWithTag:kamountLblTag];
    amountLbl.frame = CGRectMake(5, 20, 35, requiredHeight);
    amountLbl.text = amountTxt;





    if ([[[rePointer objectAtIndex:r] objectForKey:@"count"] intValue] > 0) {

        NSString *mergedTxt = [[NSString alloc]initWithString:@"Count"];
        boundingSize = CGSizeMake(35, 100);
        sysFont = [UIFont systemFontOfSize:12]; 
        requiredSize = [mergedTxt sizeWithFont:sysFont constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
        requiredHeight = requiredSize.height;


        UILabel *mergeLbl = (UILabel*)[cell viewWithTag:kMergeLblTag];
        mergeLbl.frame = CGRectMake(5, 50, 35, requiredHeight);
        mergeLbl.text = mergedTxt;
        [mergedTxt release];

    }else {

        UILabel *mergeLbl = (UILabel*)[cell viewWithTag:kMergeLblTag];
        mergeLbl.frame = CGRectZero;
        mergeLbl.text = @"";

    }



    NSString *type;

    if (![[[rePointer objectAtIndex:r] objectForKey:@"type"] isEqualToString:@"NotSet"]) {
        if ([[[rePointer objectAtIndex:r] objectForKey:@"type"] isEqualToString:@"[XYZ]"]) {
            type = @"X";
        }else{
            int typeLength = [[[rePointer objectAtIndex:r] objectForKey:@"type"] length];
            type = [[[rePointer objectAtIndex:r] objectForKey:@"type"] substringWithRange:NSMakeRange(1, typeLength-2)];
        }


        UILabel *typeLbl = (UILabel*)[cell viewWithTag:kTypeLblTag];
        typeLbl.frame = CGRectMake(5, 65, 35, 20);
        typeLbl.text = type;

    }else {
        UILabel *typeLbl = (UILabel*)[cell viewWithTag:kTypeLblTag];
        typeLbl.frame = CGRectZero;
        typeLbl.text = @"";
    }






    NSString *titleTxt = [[NSString alloc]initWithString:[[[rePointer objectAtIndex:r] objectForKey:@"h_title"]stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]];


    boundingSize = CGSizeMake(190, 1000);
    sysFont = [UIFont systemFontOfSize:14];

    requiredSize = [titleTxt sizeWithFont:sysFont constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
    requiredHeight = requiredSize.height;

    CGFloat titleHeight = requiredHeight;

    UILabel *titleLbl = (UILabel*)[cell viewWithTag:kTitleLblTag];
    titleLbl.frame = CGRectMake(50, 5, 190, requiredHeight);
    titleLbl.text = titleTxt;
    [titleTxt release];





    NSString *title2Txt = [[NSString alloc]initWithString:[[[rePointer objectAtIndex:r] objectForKey:@"title2"]stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]];

    sysFont = [UIFont systemFontOfSize:12];
    requiredSize = [title2Txt sizeWithFont:sysFont constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
    requiredHeight = requiredSize.height;

    UILabel *title2Lbl = (UILabel*)[cell viewWithTag:ktitle2LblTag];
    title2Lbl.frame = CGRectMake(50, titleHeight + 10, 190, requiredHeight);
    title2Lbl.text = title2Txt;
    [title2Txt release];




    /*
    CGFloat height = [[[rePointer objectAtIndex:r] objectForKey:@"h_title"] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(190, 1000) lineBreakMode:UILineBreakModeWordWrap].height;
    height += [[[rePointer objectAtIndex:r] objectForKey:@"title2"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(190, 1000) lineBreakMode:UILineBreakModeWordWrap].height;
    height += 20;
    */

    cell.contentView.backgroundColor = clearColor;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    NSLog(@"cellForRowAtIndexPath");




    /*
    cell.backgroundView.frame = CGRectMake(0, 0, 320, height-1);
    cell.backgroundView.backgroundColor = bgColor;
    */



    return cell;

}

And finally the heightForRowAtIndexPath:

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    


    NSUInteger row = [indexPath row];
    NSUInteger section = [indexPath section];
    row += section*100;

    NSUInteger rejectsIndex = [indexPath row];

    if (row < [results count]) {
        CGFloat height = [[[results objectAtIndex:row] objectForKey:@"h_title"] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(190, 1000) lineBreakMode:UILineBreakModeWordWrap].height;
        height += [[[results objectAtIndex:row] objectForKey:@"title2"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(190, 1000) lineBreakMode:UILineBreakModeWordWrap].height;
        height += 20;
        return MAX(90, height);
    }else {
        CGFloat height = [[[rejects objectAtIndex:rejectsIndex] objectForKey:@"h_title"] sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(190, 1000) lineBreakMode:UILineBreakModeWordWrap].height;
        height += [[[rejects objectAtIndex:rejectsIndex] objectForKey:@"title2"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(190, 1000) lineBreakMode:UILineBreakModeWordWrap].height;
        height += 20;

        return MAX (90, height);
    }


}

Thanks a lot for any advice!

  • 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-26T11:36:10+00:00Added an answer on May 26, 2026 at 11:36 am

    Turned out that it was an iOS bug.

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

Sidebar

Related Questions

I have a UITableView which sometimes has only a few rows. I would like
I have a UITableView which loads its data from the web. It takes a
I have a UITableView which loads through it's navigationController a new viewcontroller. This code
I have a UITableView which generates its data from a pList. I have a
I have a UITableView which downloads its tableviewcells images from a server. I observed
I have a UITableView which uses a UIView subclass for its backgroundView and selectedBackgroundView
I have a UITableView which is populated by an array, I have a button
I have a UITableView which displays about 5 cells at a time, yet in
I have a grouped UITableView which displays a number of cells, which includes both
I have an array of objects which populate a UITableView . When a user

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.