Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone: Adding subviews to Cell ContentView overwrites cell texts on scrolling
    primarykey
    data
    text
    <p>I have used Cell.ContentView in my implementation for customizing the cell contents. It works fine but the only problem is when I have many cells and I scroll them up and down, the cell contents gets overwritten into the cells just become hidden followed by visible. Suppose I scroll first cell up and then again takes it down, the last cell's contents gets overwritten on first cell!!</p> <p>I debugged enough on this but couldn't find the exact solution. I tried checking Cell.ContentView.SubViews count and if it 0 then only add other subviews. This doesn't display any cell contents until I scroll them up and down but once contents appeared, it doesn't overwrite..Little bit strange..!! I also made sure that I am using reusing the cell correctly. Following is my code that adds subviews into cell's contentview. Please let me know how could I get rid of this issue.</p> <p>P.S: Don't worry about the variables and calculations I have done. Assume that it returns correct values. :)</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSInteger totalAvailableSpace = IPHONE_DISPLAY_WIDTH - iconSize - accesorySize - 10; NSInteger lableHeight = [[cellDetails objectForKey:@"TableItemTextFontSize"] intValue] * 2 + 10; UILabel *textLabel = nil; textLabel = [[[UILabel alloc] initWithFrame:CGRectMake(iconSize+12, self.tableCellHeight/2 - lableHeight/2, totalAvailableSpace * 0.8, lableHeight)] autorelease]; textLabel.numberOfLines = 2; textLabel.lineBreakMode = UILineBreakModeWordWrap; textLabel.textAlignment = UITextAlignmentLeft; textLabel.text = [cellDetails objectForKey:@"TableItemMainText"]; if ([textLableColor scanHexInt:&amp;hex]) { textLabel.textColor = UIColorFromRGB(hex); } textLabel.font = [UIFont fontWithName:[cellDetails objectForKey:@"TableItemTextFontName"] size:[[cellDetails objectForKey:@"TableItemTextFontSize"] intValue]]; [cell.contentView addSubview:textLabel]; textLabel.backgroundColor = [UIColor clearColor]; lableHeight = [[cellDetails objectForKey:@"TableItemDetailTextFontSize"] intValue] * 2 + 10; UILabel *detailTextLabel = nil; detailTextLabel = [[[UILabel alloc] initWithFrame:CGRectMake(iconSize+10+totalAvailableSpace * 0.8+5, self.tableCellHeight/2 - lableHeight/2, totalAvailableSpace * 0.2 - 10, lableHeight)] autorelease]; detailTextLabel.numberOfLines = 2; detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; detailTextLabel.textAlignment = UITextAlignmentLeft; detailTextLabel.text = [cellDetails objectForKey:@"TableItemDetailText"]; if ([detailTextLableColor scanHexInt:&amp;hex]) { detailTextLabel.textColor = UIColorFromRGB(hex); } detailTextLabel.font = [UIFont fontWithName:[cellDetails objectForKey:@"TableItemDetailTextFontName"] size:[[cellDetails objectForKey:@"TableItemDetailTextFontSize"] intValue]]; [cell.contentView addSubview:detailTextLabel]; detailTextLabel.backgroundColor = [UIColor clearColor]; return cell; } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload