Paparazzi 2: Deleting a row from a table view

13 views
Skip to first unread message

JoseO

unread,
Mar 11, 2010, 1:01:17 AM3/11/10
to iPhone Application Development Auditors
I was just about to post this message:

----------
For the extra credit piece, I'm trying to delete a photo from my table
view using the Edit/Done built-in flow, but my application crashes
with this error message:

Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: '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 (1), plus or minus
the number of rows inserted or deleted from that section (0 inserted,
1 deleted).'

when invoking this line of code in the 'commitEditingStyle' method:

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:YES];

This method is calling the 'numberOfRowsInSection' method, which calls
the fetchedResultsController to return the number of rows for the
section, but is returning the number of rows prior to the deletion.
----------

when I realized that fetchedResultsController caches its results. So,
before calling the 'deleteRowsAtIndexPaths' method, is the better
practice to call 'performFetch' on fetchedResultsController to refresh
its cache (which works, by the way; no more crashes) or to call its
'deleteCacheWithName' method? Or is there an even better alternative,
as either of these may potentially be expensive operations?

Thanks,
-Jose

danbretl

unread,
Mar 11, 2010, 7:17:24 PM3/11/10
to iPhone Application Development Auditors
I'm having this same problem and have the same questions. Anybody have
an answer?

On Mar 11, 1:01 am, JoseO <jose.g.oc...@gmail.com> wrote:
> I was just about to post this message:
>
> ----------

> For the extra credit piece, I'm trying todeletea photo from my table

JohnW

unread,
Apr 9, 2010, 3:07:15 PM4/9/10
to iPhone Application Development Auditors
I was having the same problem, but got it figured out. The following
is the ordering of the steps within the
tableView:commitEditingStyle:forRowAtIndexPath: method that worked for
me:
- Delete the managed object information from the context.
- Save the context.
- Perform a new fetch on the fetched results controller.
- Delete the table row.

Hope this helps.

Thanks,
jw

Reply all
Reply to author
Forward
0 new messages