UITableViewCell backgroundView gets reused when it shouldn't?

The problem here is that you are using the same cell identifier regardless of the position in the table view So you initially create the cells based on the indexPath. Row and the count, but you associate those cells with an identifier of @"Cell". So when you scroll down dequeueReusableCellWithIdentifier will return a cell configured for the beginning of the list (indexPath.

Row == 0 && count > 1) and use it for the end of the list You need to make sure cell identifier reflects the code at the beginning of your cell==nill if block, so that you only reuse cells that have been configured for the position in the table you are creating As Eiko points out, you are also leaking your UIView and UIImageView objects. You could stick them in the if block, release them explicitly or just make them autorelease.

The problem here is that you are using the same cell identifier regardless of the position in the table view. So you initially create the cells based on the indexPath. Row and the count, but you associate those cells with an identifier of @"Cell".

So when you scroll down dequeueReusableCellWithIdentifier will return a cell configured for the beginning of the list (indexPath. Row == 0 && count > 1) and use it for the end of the list. You need to make sure cell identifier reflects the code at the beginning of your cell==nill if block, so that you only reuse cells that have been configured for the position in the table you are creating.As Eiko points out, you are also leaking your UIView and UIImageView objects.

You could stick them in the if block, release them explicitly or just make them autorelease.

Thank you, this is exactly the answer I was looking for. – Nic Hubbard Jun 27 at 23:24 @nic-hubbard No problems :) Happy to help. – RedBlueThing Jun 27 at 23:32.

Sorry, but that code has lots of problems: You are leaking the UIView and UIImageView objects, and the whole reuse of cells is wrong, hence your problems. You should set up a new cell (with views) only in the if (cell == nil) part, and don't forget to release/autorelease your views. Then, outside of that block, you configure your cell accordingly (set its contents).

I strongly suggest to look through some of Apple's example projects!

This is just copied code from an open source example project. I was just trying to get the feel for how to use backgroundViews and ran into this problem of the cell reuse. Which Apple example would be helpful?

– Nic Hubbard Jun 27 at 23:12 Look up the docs for UITableView - there are links to several example projects. This code here can't work. :) – Eiko Jun 27 at 23:15.

UIView *backgroundView = UIView alloc initWithFrame:CGRectMake(0, 0, tableView.bounds.size. UIView *selectedBackgroundView = UIView alloc initWithFrame:CGRectMake(0, 0, tableView.bounds.size. UIImageView *backgroundImage = UIImageView alloc initWithFrame:CGRectMake(10, 0, tableView.bounds.size.

UIImageView *selectedBackgroundImage = UIImageView alloc initWithFrame:CGRectMake(10, 0, tableView.bounds.size. Asset = (Asset *)items objectAtIndex:indexPath. Frame = CGRectMake(10, 0, tableView.bounds.size.

Image = UIImage imageNamed:@"MDACCellBackgroundTop. Frame = CGRectMake(10, -1, tableView.bounds.size. Image = UIImage imageNamed:@"MDACCellBackgroundSelectedTop.

} else if (indexPath. Image = UIImage imageNamed:@"MDACCellBackgroundBottom. Image = UIImage imageNamed:@"MDACCellBackgroundSelectedBottom.

} else if (indexPath. Frame = CGRectMake(10, -1, tableView.bounds.size. Image = UIImage imageNamed:@"MDACCellBackgroundSingle.

Image = UIImage imageNamed:@"MDACCellBackgroundSelectedSingle. Image = UIImage imageNamed:@"MDACCellBackgroundMiddle. Image = UIImage imageNamed:@"MDACCellBackgroundSelectedMiddle.

LinkAvailableImageView = UIImageView alloc initWithFrame:CGRectMake(cell.contentView.bounds.size. Image = UIImage imageNamed:@"MDACLinkArrow. LinkAvailableImageView = (UIImageView *)cell.

BackgroundColor = UIColor colorWithWhite:94. Image = UIImage imageNamed:@"default-icon. Image = asset.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions