(void)moveItemAtIndex:toIndex: in BNRItemStore needed?


#1

So I just finished reading the last paragraph in Chapter 9 and it seemed to be making claims that sounded right, but I figured I’d validate it.

It didn’t seem to me that this behavior was demonstrated for this particular method earlier in the chapter.

So I commented out the method (void) moveItemAtIndex:toIndex: in BNRItemStore.h and .m and I commented it out of the method call in BNRItemsViewController.m:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
 //   [[BNRItemStore sharedStore] moveItemAtIndex:sourceIndexPath.row toIndex:destinationIndexPath.row];
}

I built it and lo and behold - the reordering still worked! WTH?


#2

Hard to define “worked”.

Did you see it move on the screen? Sure. But that’s not what the commented-out code was addressing.

Try adding more items than will fit on the screen all at once. With the list scrolled to the top, move the third item to the top.

Now scroll the list so the top items roll off the top of the screen, then scroll back down.

The commented-out code was making sure the backing store matched the screen. When you scroll the items off the top of the list and then back on, the data has to come from the backing store. But since that’s no longer in sync…


#3

Thanks for the reply.

After posting that question and working with the challenges, it finally sank in that the viewcontroller still implements the re-arrangement without a hitch (granted, up to the limits of the example you gave), its just that the book keeping of the ‘model’ that is no longer in sync without the moveItemAtIndeix:toIndex method.