Note that there are some explanatory texts on larger screens.

plurals
  1. POExpanding table view cells disappearing
    text
    copied!<p>I have cells that expand by changing their height with a setExpanded: method call.</p> <p>I then call reloadRowsAtIndexPaths: to refresh the cells.</p> <p>The problem is the cells simply disappear and randomly re-appear. I suspect this has to due with the way the indexing is working.</p> <p>If I call reloadData or beginUpdates/endUpdates the cells work as expected, but I lose the animations.</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { JVCell *cell = (JVCell*)[tableView cellForRowAtIndexPath:indexPath]; JVCell *previousCell = nil; if( previousIndexPath_ != nil ) // set to nil in viewDidLoad { previousCell = (JVCell*)[tableView cellForRowAtIndexPath:previousIndexPath_]; } // expand or collapse cell if it's the same one as last time if( previousCell != nil &amp;&amp; [previousIndexPath_ compare:indexPath] == NSOrderedSame &amp;&amp; [previousCell expandable] ) { [previousCell setExpanded:![cell expanded]]; NSArray *indexPathArray = [NSArray arrayWithObject:previousIndexPath_]; [tableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic]; } else { // collapse previous cell if( previousCell != nil &amp;&amp; [previousCell expandable] ) { if( [previousCell expanded] ) [previousCell setExpanded:NO]; NSArray *indexPathArray = [NSArray arrayWithObject:previousIndexPath_]; [tableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic]; } // expand new cell if( [cell expandable] ) { [cell setExpanded:YES]; NSArray *indexPathArray = [NSArray arrayWithObject:indexPath]; [tableView reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic]; } } previousIndexPath_ = indexPath; // works as expected, but I lose the animations //[tableView reloadData]; // works as expected, but I lose the animations //[tableView beginUpdates]; //[tableView endUpdates]; } </code></pre> <p><strong>EDIT:</strong> updated to include cellForRowAtIndexPath and heightForRowAtIndexPath methods:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; JVCellSectionData *sectionData = [sections_ objectAtIndex:section]; // NSArray of SectionData objects NSArray *cellArray = [sectionData cells]; // NSArray of cells UITableViewCell *cell = [cellArray objectAtIndex:row]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; JVCellSectionData *sectionData = [sections_ objectAtIndex:section]; NSArray *cellArray = [sectionData cells]; JVCell *cell = [cellArray objectAtIndex:row]; return [cell cellHeight]; // changed when selected with setExpanded: method } </code></pre> <p><strong>Edit 2:</strong> I made a Quicktime video of what was happening and extracted screen shots.</p> <p>What I'm attempting to do is expand a cell, not replace, insert or delete cells. Each cell has one or more subviews. The height of the cell changes depending on whether it's 'expanded' or not. The content view has the subviews added to it, and it's clipToBounds property is YES. When the cells expands or collapses the height value changes along with the frame of the cell (including background view and selected background view). I've logged all the frame values before, during and after expansion, and they are all consistent with their state and position.</p> <p><img src="https://i.stack.imgur.com/LFy2P.png" alt="sectioned table view design"></p> <p><img src="https://i.stack.imgur.com/jhjH4.png" alt="cell tapped"></p> <p><img src="https://i.stack.imgur.com/n6HSf.png" alt="cell expanding"></p> <p><img src="https://i.stack.imgur.com/xy5oJ.png" alt="cell disappeared"></p> <p><img src="https://i.stack.imgur.com/3EpRh.png" alt="cell retracts"></p> <p><img src="https://i.stack.imgur.com/x9fDR.png" alt="cell visible again"></p> <p>Keep in mind that this works normally on iOS 4.3, as shown below:</p> <p><img src="https://i.stack.imgur.com/TmeJI.png" alt="comaprison ios 4 to ios 5"></p>
 

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