views:

592

answers:

2

Problem: The separator between cells in a table view appear only for those cells shown when the view loads, and only at load time. When the tableview is scrolled down, the cells scrolled into view show no separator between them, then when the tableview is scrolled back up, the initial cells show no separator.

Details: I've got a UITableView to which I'm adding standard UITableViewCells. These cells are created with initWithFrame, frame height = 90px. I'm adding a custom view created from a nib to this cell's view, height = 90px. The cell height is specified at 90px in tableView:heightForRowAtIndexPath:.

Has anyone experienced this behavior?

A: 

I had a feeling the solution to this would be simple... I made the height of my cells 91px and the separator lines appear as they should on scroll.

jtrim
A: 

The same thing happened to and your solution didn't work.

Later I discovered that this was caused by reusing cells that were translucent. In some way the cell keep adding subview elements on top of the old ones. If you try to remove the subviews of the cell the separator is released together.

For me what worked was to create new instances for every cell, in

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

instead of

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

use

UITableViewCell *cell = [[UITableViewCell alloc] init];

Douglas Schmidt