0

I am working with a dynamic UITable with prototype cells, which is created in a storyboard in iOS 5. In this table, cell heights depend on the content of the cell and are evaluated programatically in heightForRowAtIndexPath. My issue is that in the table that is displayed cell separator lines are placed at wrong locations. Here are some facts about my program:

  • Cells contents and highlights are displayed at intended locations
  • In cellForRowAtIndexPath I use dequeueReusableCellWithIdentifier to create new cells
  • heightForRowAtIndexPath returns the correct values for all cells

Can anyone please help me figure out this problem? I found a pretty old thread discussing the very same issue a year ago, however no explanations/solutions were suggested (Please see UITableView separators drawn incorrectly through cell reuse?)

Greatly appreciate your help.

Thanks,

Anis

Community
  • 1
  • 1
Anis
  • 11
  • 1
  • I have a dynamic cell height example [here](https://github.com/wtmoose/TLIndexPathTools/blob/master/Examples/Dynamic%20Height/Dynamic%20Height/DynamicHeightTableViewController.m). I tried to replicate your problem, but could not. Could you possibly share your view controller code and perhaps some details about your storyboard: a) are you using Auto Layout, b) XML excerpt for your table view? I'd like to figure out how to reproduce this. – Timothy Moose Jul 05 '13 at 20:18
  • Hi Timothy! Hope you got my reply to your post. Apparently it was too long for a comment so I posted it as an answer instead. Not too sure how these things work in stackoverflow. Thanks, Anis – Anis Jul 10 '13 at 13:53
  • No, I had not seen your post. Unfortunately, I don't see any red flags in your code. What I would probably do here is place a breakpoint in `willDisplayCellAtIndexPath` and then do `po [cell recursiveDescription]` to print out the cell's view hierarchy. Examine this hierarchy to see if there are any cells overlapping unexpectedly. This may provide a clue. – Timothy Moose Jul 10 '13 at 14:28
  • If you're still stuck, you could try posting a sample project for us to look at. Or you can take a look at the [Dynamic Height sample project](https://github.com/wtmoose/TLIndexPathTools/blob/master/Examples/Dynamic%20Height/Dynamic%20Height/DynamicHeightTableViewController.m) in my [TLIndexPathTools library](https://github.com/wtmoose/TLIndexPathTools). You could try modifying the sample project with your data to see if it works. – Timothy Moose Jul 10 '13 at 14:31
  • Thanks Timoty, I checked the view hierarchy of the cells and everything seems fine (in terms of the frame locations for cells and cell contents). – Anis Jul 16 '13 at 20:49
  • I think my cell heights are fine. The willDisplayAtCellIndex returns the correct heights and also when I tap on a cell, it is highlighted correctly. However, the separators are not placed in correct heights. Unfortunately, the project I am working on is a rather big one with many dependencies, so I don't think I can easily cut the related sections out for upload. I will try to use your code sample to see if it works. Thanks. – Anis Jul 16 '13 at 21:34
  • Just throwing out ideas here. You might also inspect the layers to see if something looks wrong. I recently answered [this question](http://stackoverflow.com/questions/17506533/ios-grouped-tableview-transparent-cells/17507506#17507506) about grouped table cell `backgroundColor` and it turned out the solution required setting the cell's layer `backgroundColor`. – Timothy Moose Jul 16 '13 at 22:08

1 Answers1

0

Thank you for replying to my post. This behaviour is weird to me too, since I have had a dynamic cell height table working properly before. Here are The information you requested:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *currentCell = nil;

    if([indexPath section] == 0 && [indexPath row]== 0)
    {
        currentCell = [issueDetailTable dequeueReusableCellWithIdentifier:@"DetailFieldCell"];

        NSString *summaryString;

        /* Here I call a method to figure out the value for summaryString */

        /* Here I call a method to figure out the frame for summaryLabel */

        summaryLabel = (UILabel *)[currentCell viewWithTag:1];
        [summaryLabel setFrame:summaryRect];
        [summaryLabel setText:summaryString];
    }
    return currentCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    CGFloat height;

    if([indexPath section] == 0 && [indexPath row]== 0)
    {
        NSString *summaryString;

        /* Here I call the same method to figure out the value for summaryString */

        /* Here I call the same method to figure out the frame for summaryLabel */

        /* height = height of the summary label */
    }

    return height;
}

As far as the storyboard is concerned, I use prototype cells for my table; My table auto resizes and clips subviews and clears graphics context; My cells clear graphics context.

And, I was going to post a screen shot of my table view, but apparently my Stackoverflow reputation points are not sufficient! :|

Thanks again for helping me figure this out.

Best Regards, Anis

Anis
  • 11
  • 1
  • In the code above, you're returning an undefined value for `height` in `heightForRowAtIndexPath` for all rows except (0, 0). Maybe that has something to do with it. – Timothy Moose Jul 12 '13 at 20:46
  • I was actually trying to simplify my code. In my code I return values for all rows. – Anis Jul 16 '13 at 21:02