Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom UITableViewCells are not being reused on UITableView
    primarykey
    data
    text
    <p>There seems to be a ton of questions on this but I am not able to use anyone else's answers so was hoping someone could review how I am doing this. I am trying to use. I have two custom UITableViewCells which right now just have a BOOL property on them and thats it in the way of styling.</p> <p>Within my <code>cellForRowAtIndexPath</code> method based on what type of data is coming back I am styling my cells. If the data is a "month" header its a long skinny looking cell and if its a "news item" its going to be a larger white looking cell. </p> <p><img src="https://i.stack.imgur.com/NCh5O.png" alt="enter image description here"> </p> <p>When the table loads everything looks great but if I scroll down to create more cells and then scroll back up the cells are being recreated and eventually scrolling slows down because I am running out of memory.</p> <p>When I set break points the <code>dequeueReusableCellWithIdentifier</code> always returns nil so my cells are never reused which seems to be a problem.</p> <p>In this picture you can see that cells are getting stacked on top of each other and messed up:</p> <p><img src="https://i.stack.imgur.com/nfR2l.png" alt="enter image description here"></p> <p>Here my my code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *NewsCellIdentifer = @"NewsCellIdentifier"; static NSString *MonthCellIdentifier = @"MonthCellIdentifier"; NSUInteger row = [indexPath row]; NewsItem *item = [self.newsArray objectAtIndex:row]; if (item.IsMonth == YES) { NewsMonthUITableViewCell *cell = [self.mytableView dequeueReusableCellWithIdentifier:MonthCellIdentifier]; if (cell == nil) { cell = [[NewsMonthUITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MonthCellIdentifier]; } // This handles any other "date" cells to allow for different spacing styles. if (item.IsMonth) { UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 400, 20)]; av.backgroundColor = [UIColor clearColor]; av.opaque = NO; av.image = [UIImage imageNamed:@"month-bar-bkgd.png"]; UILabel *monthTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 150, 20)];; CGFloat font = 11.0f; monthTextLabel.font = [BVFont HelveticaNeue:&amp;font]; monthTextLabel.backgroundColor = [UIColor clearColor]; monthTextLabel.font = [BVFont HelveticaNeue:&amp;font]; monthTextLabel.textColor = [BVFont WebGrey]; monthTextLabel.text = item.Title; cell.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:av]; [cell.contentView addSubview:monthTextLabel]; } return cell; } else { NewsUITableViewCell *cell = [self.mytableView dequeueReusableCellWithIdentifier:NewsCellIdentifer]; if (cell == nil) { cell = [[NewsUITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NewsCellIdentifer]; } cell.contentView.backgroundColor = [UIColor clearColor]; UIView *whiteRoundedCornerView = [[UIView alloc] initWithFrame:CGRectMake(10,10,300,100)]; whiteRoundedCornerView.backgroundColor = [UIColor whiteColor]; whiteRoundedCornerView.layer.masksToBounds = NO; whiteRoundedCornerView.layer.cornerRadius = 3.0; whiteRoundedCornerView.layer.shadowOffset = CGSizeMake(-1, 1); whiteRoundedCornerView.layer.shadowOpacity = 0.5; [cell.contentView addSubview:whiteRoundedCornerView]; [cell.contentView sendSubviewToBack:whiteRoundedCornerView]; [cell.contentView addSubview:[self NewsItemThumbnailView:item]]; [cell.contentView addSubview:[self NewsItemTextView:item]]; [cell.contentView addSubview:[self NewsItemCornerIconIndicatorView:item]]; return cell; } return nil; } </code></pre> <p>Thanks for any assistance or advice!</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.
    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