AQGridView icon indicating copy to clipboard operation
AQGridView copied to clipboard

Using AQGridView with an NSFetchedResultsController

Open awmwong opened this issue 13 years ago • 11 comments

I'm having some troubles getting the the gridView to work with a FRC, primarily with the FRC delegates for inserting/updating/deleting elements.

These delegate functions provide an indexPath for the tableView functions, but AQGV expects indexSets for its insert/delete/update functions.

Could you offer some assistance?

(and yes I do realize I can call a reloadData for the entire gridView on didChangeContent, but I'd prefer a nicer solution if possible.)

awmwong avatar Dec 02 '11 19:12 awmwong

If there is only one section (no section key path), the row index can be used as the grid index. Methinks.

On Dec 3, 2011, at 3:34 AM, Anthony Wong wrote:

I'm having some troubles getting the the gridView to work with a FRC, primarily with the FRC delegates for inserting/updating/deleting elements.

These delegate functions provide an indexPath for the tableView functions, but AQGV expects indexSets for its insert/delete/update functions.

Could you offer some assistance?

(and yes I do realize I can call a reloadData for the entire gridView on didChangeContent, but I'd prefer a nicer solution if possible.)


Reply to this email directly or view it on GitHub: https://github.com/AlanQuatermain/AQGridView/issues/98

evadne avatar Dec 02 '11 20:12 evadne

Hmm, good call.

I'll give that a shot and get back..

awmwong avatar Dec 02 '11 21:12 awmwong

So creating an indexSet using [NSIndexSet indexSetWithInt[indexPath row]], kinda works?

I'm getting error messages thrown around though when the FRC starts notifying about changes.. Visible cell list is missing some items! # indicies missing

And eventually will crash with an EXC_BAD_ACCESS.

Pah! Anyone else with ideas?

awmwong avatar Dec 02 '11 21:12 awmwong

Post it. :)

On Dec 3, 2011, at 5:36 AM, Anthony Wong [email protected] wrote:

So creating an indexSet using [NSIndexSet indexSetWithInt[indexPath row]], kinda works?

I'm getting error messages thrown around though when the FRC starts notifying about changes.. Visible cell list is missing some items!

indicies missing

And eventually will crash with an EXC_BAD_ACCESS.

Pah! Anyone else with ideas?


Reply to this email directly or view it on GitHub: https://github.com/AlanQuatermain/AQGridView/issues/98#issuecomment-2996192

evadne avatar Dec 03 '11 04:12 evadne

So heres the FRC delegate...

#pragma mark - NSFetchedResultsController delegates
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {

    [self.gridView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath {


    switch(type) {

        case NSFetchedResultsChangeInsert:
            [self.gridView insertItemsAtIndices:[NSIndexSet indexSetWithIndex:[indexPath row]] withAnimation:AQGridViewItemAnimationNone];

            break;

        case NSFetchedResultsChangeDelete:
            [self.gridView deleteItemsAtIndices:[NSIndexSet indexSetWithIndex:[indexPath row]] withAnimation:AQGridViewItemAnimationNone];
            break;

        case NSFetchedResultsChangeUpdate:
            [self.gridView reloadItemsAtIndices:[NSIndexSet indexSetWithIndex:[indexPath row]] withAnimation:AQGridViewItemAnimationNone];
            break;

        case NSFetchedResultsChangeMove:
            [self.gridView deleteItemsAtIndices:[NSIndexSet indexSetWithIndex:[indexPath row]] withAnimation:AQGridViewItemAnimationNone];
            [self.gridView insertItemsAtIndices:[NSIndexSet indexSetWithIndex:[newIndexPath row]] withAnimation:AQGridViewItemAnimationNone];
            break;
    }
}


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {

    [self.gridView endUpdates];
}
#pragma mark -
#pragma mark Grid View Data Source

- (NSUInteger) numberOfItemsInGridView: (AQGridView *) aGridView
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.resultsController sections] objectAtIndex:0];

    return [sectionInfo numberOfObjects];
}

awmwong avatar Dec 03 '11 17:12 awmwong

I'm having the same problem. I did notice one thing in your code - on insertions, use newIndexPath instead of indexPath (the latter is nil on insertions). Though I don't think that will solve your problem. Please post if you figured out what's wrong.

jonruiz avatar Jan 12 '12 22:01 jonruiz

Out of curiosity, does this solve the problem for you?

https://github.com/samsoffes/ssfetchedresultscontroller

joshpaul avatar Jan 23 '12 18:01 joshpaul

I have had to put this on hold for a while, but when I get back to it I will try your suggestion and let everyone know if/how it works. Thanks!

jonruiz avatar Feb 01 '12 14:02 jonruiz

I'm using fetchedResultsController with an AQGridView, and generate indices with NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];

deeje avatar Feb 22 '12 02:02 deeje

and related, here's how I generate indexSets inside didChangeObject:

NSIndexSet  *indexSet = nil;
if (type == NSFetchedResultsChangeInsert)
    indexSet = [NSIndexSet indexSetWithIndex:newIndexPath.row];
else
    indexSet = [NSIndexSet indexSetWithIndex:indexPath.row];

deeje avatar Feb 22 '12 02:02 deeje

Thanks deeje and joshpaul - once I can get this project off the back-burner, I have two good suggestions and I'll report back on the results!

jonruiz avatar Feb 26 '12 16:02 jonruiz