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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:26:31+00:00 2026-05-28T06:26:31+00:00

I have a problem with my UITableViewCell’s. I am developing an application where certain

  • 0

I have a problem with my UITableViewCell’s. I am developing an application where certain posts in a feed may contain an image, and the button clicked will also need to contain a ‘tag’ number depending on which row of the table it is as I have an array of images downloaded.

The problem lies when I am scrolling (as you have already guessed) the table. The image loads fine, however when I scroll up/down the image will then go above other cells, and when the cell is shown back on the screen, the image will quickly change it’s position to the proper position etc.

Here’s the code for my UITableView:

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

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

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier 
{
    CGRect rect = [self.tableView bounds];
    CGRect CellFrame = CGRectMake(0.0f, 0.0f, rect.size.width, 10.0f);
    CGRect TitleFrame = CGRectMake(55.0f, 10.0f, 240.0f, 15.0f);
    CGRect TextFrame = CGRectMake(55.0f, 25.0f, 250.0f, 15.0f);
    CGRect PinFrame = CGRectMake(21.0f, 10.0f, 30.0f, 30.0f);
    CGRect ViewFrame = CGRectMake(50.0f, 35.0f, 260.0f, 0.0f);
    CGRect CommentsFrame = CGRectMake(300.0f, 10.0f, 20.0f, 15.0f);
    UILabel * lblTemp;

    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    [cell setFrame:CellFrame];

    lblTemp = [[UILabel alloc] initWithFrame:TitleFrame];
    lblTemp.tag = 1;
    lblTemp.numberOfLines = 0;
    lblTemp.opaque = NO;
    lblTemp.font = [UIFont systemFontOfSize:13.0f];
    lblTemp.backgroundColor = [UIColor clearColor];
    lblTemp.textColor = [UIColor blackColor];
    lblTemp.textAlignment = UITextAlignmentLeft;
    lblTemp.shadowColor = [UIColor whiteColor];
    lblTemp.shadowOffset = CGSizeMake(0, 1);
    [cell.contentView addSubview:lblTemp];

    lblTemp = [[UILabel alloc] initWithFrame:TextFrame];
    lblTemp.tag = 2;
    lblTemp.numberOfLines = 0;
    lblTemp.lineBreakMode = UILineBreakModeWordWrap;
    lblTemp.adjustsFontSizeToFitWidth = NO;
    lblTemp.font = [UIFont systemFontOfSize:13.0f];
    lblTemp.textColor = [UIColor lightGrayColor];
    lblTemp.backgroundColor = [UIColor clearColor];
    lblTemp.shadowColor = [UIColor whiteColor]; 
    lblTemp.shadowOffset = CGSizeMake(0, 1);
    [cell.contentView addSubview:lblTemp];

    lblTemp = [[UILabel alloc] initWithFrame:CommentsFrame];
    lblTemp.tag = 5;
    lblTemp.numberOfLines = 1;
    lblTemp.font = [UIFont systemFontOfSize:13.0f];
    lblTemp.textColor = [UIColor lightGrayColor];
    lblTemp.backgroundColor = [UIColor whiteColor];
    lblTemp.shadowColor = [UIColor whiteColor];
    lblTemp.shadowOffset = CGSizeMake(0, 1);
    [cell.contentView addSubview:lblTemp];

    UIImageView * imgTemp = [[UIImageView alloc] initWithFrame:PinFrame];
    imgTemp.tag = 3;
    [cell.contentView addSubview:imgTemp];

    UIView * viewTemp = [[UIView alloc] initWithFrame:ViewFrame];
    viewTemp.tag = 4;
    [viewTemp setBackgroundColor:[UIColor whiteColor]];
    [cell.contentView addSubview:viewTemp];

    return cell;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"Cell";

    UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //UITableViewCell * cell = [self getCellContentView:CellIdentifier];

    if (cell == nil) {
        cell = [self getCellContentView:CellIdentifier];
    } else {
        [cell.contentView viewWithTag:999];
    }

    cell.backgroundColor = [UIColor clearColor];

    UILabel * title         = (UILabel *)[cell viewWithTag:1];
    UILabel * journey       = (UILabel *)[cell viewWithTag:2];
    UIImageView * pin       = (UIImageView *) [cell viewWithTag:3];
    UILabel * comments      = (UILabel *)[cell viewWithTag:5];

    title.text = [NSString stringWithFormat:@"%@", [[feed objectAtIndex:indexPath.row] objectForKey:@"comment"]];
    [title sizeToFit];
    title.frame = CGRectMake(title.frame.origin.x, title.frame.origin.y, 240, title.frame.size.height);

    if ([[feed objectAtIndex:indexPath.row] objectForKey:@"weather_desc"] != [NSNull null] ||
        [[feed objectAtIndex:indexPath.row] objectForKey:@"weather_temp"] != [NSNull null]) {
            journey.text = [NSString stringWithFormat:@"It's %@ and %@°C.", [[feed objectAtIndex:indexPath.row] objectForKey:@"weather_desc"], [[feed objectAtIndex:indexPath.row] objectForKey:@"weather_temp"]];
    } else {
        journey.text = [NSString stringWithFormat:@"%@", [[[feed objectAtIndex:indexPath.row] objectForKey:@"journey"] objectForKey:@"name"]];
    }
    journey.frame = CGRectMake(journey.frame.origin.x, 10 + title.frame.size.height, 240, 15);

    if ([[feed objectAtIndex:indexPath.row] objectForKey:@"latitude"] != [NSNull null]) {
        pin.image = [UIImage imageNamed:@"LocationPin.png"];
    } else {
        pin.image = [UIImage imageNamed:@"Pin.png"];
    }

    if ([[feed objectAtIndex:indexPath.row] objectForKey:@"image_file_size"] != [NSNull null]) {
        NSString * text = [NSString stringWithFormat:@"%@", [[feed objectAtIndex:indexPath.row] objectForKey:@"comment"]];
        CGFloat height = [text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(250, 1500) lineBreakMode:UILineBreakModeWordWrap].height;

        UIImage * myImage = [images objectForKey:[NSString stringWithFormat:@"%i", indexPath.row]];

        UIButton * button = [[UIButton alloc] initWithFrame:CGRectZero];
        [button setBackgroundImage:myImage forState:UIControlStateNormal];
        [button setFrame:CGRectMake(title.frame.origin.x + 55.0f, 40.0f + height, 250.0f, myImage.size.height)];
        [button setTag:10 + indexPath.row];
        [button addTarget:self action:@selector(imagePressed:) forControlEvents:UIControlEventTouchUpInside];
        [cell addSubview:button];

        UIView * backView = (UIView *) [cell viewWithTag:4];
        [backView setFrame:CGRectMake(title.frame.origin.x + 50.0f, 35.0f + height, 260.0f, myImage.size.height + 10.0f)];
    } else {
        UIView * backView = (UIView *) [cell viewWithTag:4];
        [backView setFrame:CGRectZero];
        [backView setBackgroundColor:[UIColor clearColor]];
    }

    comments.text = [NSString stringWithFormat:@"%i", [[[feed objectAtIndex:indexPath.row] objectForKey:@"comments"] count]];

    UIImage * background = [UIImage imageNamed:@"CellBackground.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:background];
    imageView.contentMode = UIViewContentModeScaleToFill;
    [cell setBackgroundView:imageView];

    return cell;
}

- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    MilestoneView * milestoneView = [[MilestoneView alloc] initWithNibName:@"MilestoneView" bundle:nil];
    [milestoneView setMilestone:[feed objectAtIndex:indexPath.row]];
    [self.navigationController pushViewController:milestoneView animated:YES];
}

- (CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSString * text = [NSString stringWithFormat:@"%@", [[feed objectAtIndex:indexPath.row] objectForKey:@"comment"]];
    CGFloat height = [text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(240, 1500) lineBreakMode:UILineBreakModeWordWrap].height;

    if ([[feed objectAtIndex:indexPath.row] objectForKey:@"image_file_size"] != [NSNull null]) {
        UIImage * myImage = [images objectForKey:[NSString stringWithFormat:@"%i", indexPath.row]];
        height += myImage.size.height + 15.0f;
    }

    return height + 37;
}

I am also using Apple’s inbuilt ‘ARC’ with iOS 5.0.

Kind regards,

Dominic

  • 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-28T06:26:32+00:00Added an answer on May 28, 2026 at 6:26 am

    Ended up fixing the solution by doing the following simple code:

    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview]superview]];
    

    I used the UIButton sender to get the cell that it was within. I also pulled out all the modifications of the .tag’s and kept them at the same number.

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

Sidebar

Related Questions

have a little problem with this code: UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
I have the next problem. In one of the cells (UITableViewCell) I need to
I have problem with fancybox. I want to write a function that will run
I have a UITextField inside a UITableViewCell. It will not activate on the iPad
I'll show you my problem by image. I have tableView in which i customize
I have such a problem: I have a UITextField in my UITableViewCell . When
I have a simple problem. I created a custom UITableViewCell that includes a UISwitch
I have problem with loading images from the Documents folder of iPhone application into
I have one iphone application in which i am adding uitableview inside uitableviewcell.in that
I have a small problem with the UITableviewCell. i'm using the code: UIView *cellBackView

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.