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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:31:29+00:00 2026-05-17T16:31:29+00:00

I have the following problem: I have a UITableView with some Text and some

  • 0

I have the following problem:

I have a UITableView with some Text and some Images as content. The TextLabel of the cell displays the text and I add a UIView with some UIImageViews as its subview to the cells contentview.

Everything works fine until I delete some cells. What happens is, I delete a cell (lets say the first) from the table, reload its data and e.g. then second cell moves one further up BUT! the UIView to the right contains the content from the first (deleted) cell.

I dont know why this happens – though I assume somethings wrong in me cellForRowAtIndexPath callback method.

I’ll paste some code to make it clearer.

What I can do, is unload the controller and load it again – then the images contain the correct content again….

Heres my code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {



static NSString *MyIdentifierUNCHECK = @"MyIdentifierUNCHECK";


MyStuff *m = [allObjects objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:MyIdentifierUNCHECK];
    UIView *v;    
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifierUNCHECK] autorelease];
        v = [[[UIView alloc] initWithFrame:CGRectMake(5.0, 5.0, 70.0, 70.0)] autorelease];

        v.contentMode = UIViewContentModeScaleAspectFill;
        [v addSubview:[[UIImageView alloc] init]];//some image view
        [cell.contentView addSubview:v];
    }

    cell.textLabel.text = m.name;
    cell.textLabel.numberOfLines = 0;
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:14.0];
    cell.imageView.image = [UIImage imageNamed:@"checkbox.png"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
  • 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-17T16:31:30+00:00Added an answer on May 17, 2026 at 4:31 pm

    I am assuming by “view in the right” you mean the view that u instanciate there for your cell…The problem here occurs because you reuse cells and are not resetting the UIView for each cell, you will see your same problem occur if you have enough cells that you can scroll through them.
    When you reuse cells you must always assume they have dirty data and should reload them with the right data, in your case, your mistake is in this snippet:

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifierUNCHECK] autorelease];
        v = [[[UIView alloc] initWithFrame:CGRectMake(5.0, 5.0, 70.0, 70.0)] autorelease];
    
        v.contentMode = UIViewContentModeScaleAspectFill;
        [v addSubview:[[UIImageView alloc] init]];//some image view
        [cell.contentView addSubview:v];
    }
    

    You are only instantiating the view in the cell when its first allocated, so this is whats happening…
    1- You Make all your cells initially and make their “right view”
    2- You delete a cell
    3- For your second cell, the system is reusing the UITableViewCell that you created as your first cell
    4- Since the cell isnt nil the UIView isnt being set and what you see is the first cells UIView for the second cell

    Since you are not resetting the cells UIView, you are seeing the wrong view in the cell instead of the one you expect.

    In order to fix this you can either choose not to reuse cells OR you can move the code that adds the UIView to occur everytime cellForRowAtIndexPath is called, that way the right UIView will be loaded with the right cell

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

Sidebar

Related Questions

No related questions found

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.