Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView's reloadRowsAtIndexPaths: seems to break insertRowsAtIndexPaths:
    primarykey
    data
    text
    <p>I have a <code>UITableView</code> into which the user can insert new rows. When this happens, I want to reload all of the old rows in the table. One solution would be to just call <code>reloadData</code> as soon as the insertion takes place, which totally works, but this means I don't get the insertion animation.</p> <p>So when the user hits the "add row" button, I call <code>reloadRowsAtIndexPaths:</code> with every index path except the one just inserted. Then I call <code>insertRowsAtIndexPaths:</code> with only the newly inserted row. Reasonable, right?</p> <p>This causes the app to crash with the following explanation:</p> <blockquote> <p>Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).</p> </blockquote> <p>This happens, as you can see in this example, even when <code>reloadRowsAtIndexPaths</code> is passed an empty array of index paths.</p> <p>Ah! I need to wrap the two calls with <code>beginUpdates</code> and <code>endUpdates</code>. Fair enough. But now the animation is completely broken.</p> <p>I'm performing the reload with a <code>UITableViewRowAnimationFade</code> and the insertion with a <code>UITableViewRowAnimationAutomatic</code>. But during the animation, the heights of every row changes, creating this weird flickery effect that looks just terrible. What's the correct way to animate these changes?</p> <h2>Edit:</h2> <p>From the docs for <code>reloadRowsAtIndexPaths:withRowAnimation:</code>:</p> <blockquote> <p>Reloading a row causes the table view to ask its data source for a new cell for that row. The table animates that new cell in as it animates the old row out. Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.</p> </blockquote> <p>I think that, in my application, manually updating each cell is the right way to go. However, I am still perturbed by this bizarre animation bug, and would like to know what the cause of it is / what I would do if I did "want to alert the user that the value of the cell is changing."</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