Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do my table view cells disappear when reloaded using reloadRowsAtIndexPaths?
    primarykey
    data
    text
    <p>I have a bare-bones sample project here:</p> <p><a href="http://dl.dropbox.com/u/7834263/ExpandingCells.zip" rel="noreferrer">http://dl.dropbox.com/u/7834263/ExpandingCells.zip</a></p> <p>In this project, a UITableView has a custom UITableViewCell. In each cell are 3 UIViews containing a label.</p> <p>The goal is to expand the cell when tapped, then collapse it when tapped again. The cell itself must change it’s height to expose the subviews. Inserting or removing rows is unacceptable.</p> <p>The demo project works almost as expected. In fact, in iOS 4.3 it works perfect. Under iOS 5, however, when the rows collapse, the previous cells magically disappear.</p> <p>To re-create the problem, run the project in the simulator or device with iOS 5 and tap the first cell to expand it. Then tap the cell again to collapse it. Finally, tap the cell directly underneath it. The previous one disappears.</p> <p>Continuing the tapping for each cell in the section will cause all the cells to disappear, to where the entire section is missing.</p> <p>I’ve also tried using reloadData instead of the current setup, but that ruins the animations and feels a bit like a hack anyway. reloadRowsAtIndexPaths should work, but the question is why doesn’t it?</p> <p>See images of what's happening below:</p> <p>Table appears:</p> <p><img src="https://i.stack.imgur.com/TAHAO.png" alt="table appears"></p> <p>Cell expands:</p> <p><img src="https://i.stack.imgur.com/TTI4D.png" alt="table expands"></p> <p>Cell collapses:</p> <p><img src="https://i.stack.imgur.com/TAHAO.png" alt="table collapses"></p> <p>Cell disappears (when tapping the cell underneath):</p> <p><img src="https://i.stack.imgur.com/EYmiQ.png" alt="cell disappears"></p> <p>Keep repeating until the entire section disappears:</p> <p><img src="https://i.stack.imgur.com/nQ2m0.png" alt="section disappears"></p> <p><strong>EDIT:</strong> Overriding the alpha is a hack, but works. Here is another 'hack' that fixes it as well but WHY does it fix it?</p> <p>JVViewController.m line 125:</p> <pre><code>if( previousIndexPath_ != nil ) { if( [previousIndexPath_ compare:indexPath] == NSOrderedSame ) currentCellSameAsPreviousCell = YES; JVCell *previousCell = (JVCell*)[self cellForIndexPath:previousIndexPath_]; BOOL expanded = [previousCell expanded]; if( expanded ) { [previousCell setExpanded:NO]; [indicesToReload addObject:[previousIndexPath_ copy]]; } else if( currentCellSameAsPreviousCell ) { [previousCell setExpanded:YES]; [indicesToReload addObject:[previousIndexPath_ copy]]; } //[indicesToReload addObject:[previousIndexPath_ copy]]; } </code></pre> <p><strong>EDIT 2:</strong></p> <p>Made a few minor changes to demo project, worth checking out and reviewing JVViewController didSelectRowAtIndexPath method.</p>
    singulars
    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