kolinkrewinkel / KKGridView

Deprecated: Grid view library for iOS.
https://github.com/kolinkrewinkel/KKGridView
Other
818 stars 152 forks source link

Extra Cells Added As Subviews, Then Abandoned, When Using NSFetchedResultsController #97

Closed ashfurrow closed 12 years ago

ashfurrow commented 12 years ago

I've integrated the KKGridView into my project, but I'm having a problem with extra cells being added to the grid view, then abandoned as subviews. This isn't apparent in the example project because the background colours of the grid view and cells are both white, so they're effectively invisible. My grid view has a transparent background, on top of an image, so it's clear in this screenshot: Screenshot What's worse is that the extra cells are actually on top of the cells underneath. After setting a breakpoint in _layoutVisibleCells, I can produce this output in gdb:

(gdb) po [self visibleIndexPaths]
<__NSArrayM 0x8e3b720>(
KKIndexPath {Index: 0; Section: 0},
KKIndexPath {Index: 1; Section: 0},
KKIndexPath {Index: 2; Section: 0},
KKIndexPath {Index: 3; Section: 0},
KKIndexPath {Index: 4; Section: 0},
KKIndexPath {Index: 5; Section: 0},
KKIndexPath {Index: 6; Section: 0},
KKIndexPath {Index: 7; Section: 0},
KKIndexPath {Index: 8; Section: 0},
KKIndexPath {Index: 9; Section: 0},
KKIndexPath {Index: 10; Section: 0},
KKIndexPath {Index: 11; Section: 0},
KKIndexPath {Index: 12; Section: 0},
KKIndexPath {Index: 13; Section: 0},
KKIndexPath {Index: 14; Section: 0},
KKIndexPath {Index: 15; Section: 0},
KKIndexPath {Index: 16; Section: 0},
KKIndexPath {Index: 17; Section: 0},
KKIndexPath {Index: 18; Section: 0},
KKIndexPath {Index: 19; Section: 0},
KKIndexPath {Index: 20; Section: 0},
KKIndexPath {Index: 21; Section: 0},
KKIndexPath {Index: 22; Section: 0},
KKIndexPath {Index: 23; Section: 0}
)

But when I examine the subviews, I get the following:

(gdb) po [self subviews]
<__NSArrayM 0x8c46bc0>(
<KKGridViewCell: 0x8c568c0; frame = (83 459; 75 75); layer = <CALayer: 0x8c55e60>>,
<KKGridViewCell: 0x8c559f0; frame = (83 380; 75 75); layer = <CALayer: 0x8c55630>>,
<KKGridViewCell: 0x8c46380; frame = (83 301; 75 75); layer = <CALayer: 0x8c4d590>>,
<KKGridViewCell: 0xe55e4f0; frame = (162 380; 75 75); layer = <CALayer: 0xe56dca0>>,
<KKGridViewCell: 0xe573c10; frame = (162 459; 75 75); layer = <CALayer: 0xe56df90>>,
<KKGridViewCell: 0xe749d90; frame = (4 301; 75 75); layer = <CALayer: 0xe749130>>,
<KKGridViewCell: 0xe748ed0; frame = (4 459; 75 75); layer = <CALayer: 0xe7481f0>>,
<KKGridViewCell: 0xe7445e0; frame = (4 380; 75 75); layer = <CALayer: 0xe744160>>,
<KKGridViewCell: 0x8c54630; frame = (241 301; 75 75); layer = <CALayer: 0x8c4e0e0>>,
<KKGridViewCell: 0x8c4dcc0; frame = (241 222; 75 75); layer = <CALayer: 0x8c4fb70>>,
<KKGridViewCell: 0x8c53600; frame = (162 301; 75 75); layer = <CALayer: 0x8c52a20>>,
<KKGridViewCell: 0x8c52820; frame = (4 64; 75 75); layer = <CALayer: 0x8c51bc0>>,
<KKGridViewCell: 0x8c518e0; frame = (241 459; 75 75); layer = <CALayer: 0x8c50d00>>,
<KKGridViewCell: 0x8c50b00; frame = (162 143; 75 75); layer = <CALayer: 0x8c4fe90>>,
<KKGridViewCell: 0x8c4fc00; frame = (83 222; 75 75); layer = <CALayer: 0x8c4ef20>>,
<KKGridViewCell: 0x8c4ec70; frame = (4 222; 75 75); layer = <CALayer: 0x8c4eb50>>,
<KKGridViewCell: 0x89a15c0; frame = (83 143; 75 75); layer = <CALayer: 0x8987420>>,
<KKGridViewCell: 0x89a09c0; frame = (162 222; 75 75); layer = <CALayer: 0x899fe50>>,
<KKGridViewCell: 0x899fad0; frame = (241 380; 75 75); layer = <CALayer: 0x899e630>>,
<KKGridViewCell: 0x8997360; frame = (4 143; 75 75); layer = <CALayer: 0x8995d90>>,
<KKGridViewCell: 0xe574180; frame = (241 143; 75 75); layer = <CALayer: 0xe5741e0>>,
<KKGridViewCell: 0xe593270; frame = (241 64; 75 75); layer = <CALayer: 0xe5785a0>>,
<KKGridViewCell: 0xe590a60; frame = (162 64; 75 75); layer = <CALayer: 0xe593610>>,
<KKGridViewCell: 0xe56b510; frame = (83 64; 75 75); layer = <CALayer: 0xe597b20>>,
<KKGridViewCell: 0xe59c0e0; frame = (241 459; 75 75); layer = <CALayer: 0xe59c140>>,
<KKGridViewCell: 0xe593650; frame = (241 459; 75 75); layer = <CALayer: 0xe5936b0>>,
<KKGridViewCell: 0xe58c1f0; frame = (241 459; 75 75); layer = <CALayer: 0xe58c250>>,
<KKGridViewCell: 0xe587e10; frame = (241 459; 75 75); layer = <CALayer: 0xe587e70>>,
<KKGridViewCell: 0xe57fe40; frame = (241 459; 75 75); layer = <CALayer: 0xe57fea0>>,
<KKGridViewCell: 0xe57dfc0; frame = (241 459; 75 75); layer = <CALayer: 0xe57e020>>,
<KKGridViewCell: 0xe57b330; frame = (241 459; 75 75); layer = <CALayer: 0xe57b390>>,
<KKGridViewCell: 0xe56fd80; frame = (241 459; 75 75); layer = <CALayer: 0xe56fde0>>,
<KKGridViewCell: 0xe56d750; frame = (241 459; 75 75); layer = <CALayer: 0xe56d7b0>>,
<KKGridViewCell: 0xe56d6a0; frame = (241 459; 75 75); layer = <CALayer: 0xe55d4a0>>,
<KKGridViewCell: 0x8993be0; frame = (241 459; 75 75); layer = <CALayer: 0x8993b20>>,
<KKGridViewCell: 0x8993220; frame = (241 459; 75 75); layer = <CALayer: 0x8993160>>,
<KKGridViewCell: 0x8992870; frame = (241 459; 75 75); layer = <CALayer: 0x89927b0>>,
<KKGridViewCell: 0x89921d0; frame = (241 459; 75 75); layer = <CALayer: 0x898cc40>>,
<KKGridViewCell: 0x8991300; frame = (241 459; 75 75); layer = <CALayer: 0x8991240>>,
<KKGridViewCell: 0x89908f0; frame = (241 459; 75 75); layer = <CALayer: 0x8990830>>,
<KKGridViewCell: 0x898ff30; frame = (241 459; 75 75); layer = <CALayer: 0x898fe70>>,
<KKGridViewCell: 0x898f520; frame = (241 459; 75 75); layer = <CALayer: 0x898f460>>,
<KKGridViewCell: 0x898eb70; frame = (241 459; 75 75); layer = <CALayer: 0x898eab0>>,
<KKGridViewCell: 0x898e1a0; frame = (241 459; 75 75); layer = <CALayer: 0x898e0e0>>,
<KKGridViewCell: 0x898d740; frame = (241 459; 75 75); layer = <CALayer: 0x898d680>>,
<KKGridViewCell: 0x898cd90; frame = (241 459; 75 75); layer = <CALayer: 0x8989aa0>>,
<KKGridViewCell: 0x898c300; frame = (241 459; 75 75); layer = <CALayer: 0x898c240>>,
<KKGridViewCell: 0x898b930; frame = (241 459; 75 75); layer = <CALayer: 0x898b870>>,
<UIImageView: 0x896c740; frame = (0 475; 320 5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x896d7e0>>,
<UIView: 0x896ac20; frame = (0 0; 320 60); alpha = 0.0333334; layer = <CALayer: 0x896ac50>>,
<UIImageView: 0x895efa0; frame = (313 65.5; 5 365); opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x896d730>>
)

The issue appears to be using an NSFetchedResultsController:

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
    if (controller != self.fetchedResultsController)
        return;
    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.gridView insertItemsAtIndexPaths:[NSArray arrayWithObject:[KKIndexPath indexPathWithNSIndexPath:newIndexPath]] withAnimation:KKGridViewAnimationNone];
            break;
        case NSFetchedResultsChangeUpdate:
            [self.gridView reloadItemsAtIndexPaths:[NSArray arrayWithObject:[KKIndexPath indexPathWithNSIndexPath:indexPath]]];
            break;
    }
}

If I changed the code for dealing with inserted rows to just reloadData, everything works fine. Could someone please advise?

jonsterling commented 12 years ago

@kolinkrewinkel Do you think you can address this? I'm a bit busy for a while.

ashfurrow commented 12 years ago

Is there any update on this? Even if you point me in the right direction, I can take another look. The codebase is pretty hefty and I honestly don't even know where to start.

jonsterling commented 12 years ago

Ash,

Sorry for the radio silence; I was hoping that @kolinkrewinkel would take a look at this, since I believe he wrote the part of the code that deals with this.

If I can't get him to deal with this, I'll see if I can fix this for you on the weekend; I a little swamped right now.

In the meanwhile, do you think you could put together a test project?

Thanks for your patience, Jon

Sent from my iPhone

On Feb 2, 2012, at 11:23 AM, Ash Furrowreply@reply.github.com wrote:

Is there any update on this? Even if you point me in the right direction, I can take another look. The codebase is pretty hefty and I honestly don't even know where to start.


Reply to this email directly or view it on GitHub: https://github.com/kolinkrewinkel/KKGridView/issues/97#issuecomment-3784390

ashfurrow commented 12 years ago

Thanks for getting back to me so quickly - I've downloaded the original source and will throw together a demo project this afternoon.

Thanks again, Ash

ashfurrow commented 12 years ago

Or maybe the issue was already solved - I couldn't reproduce with the latest, updated my project's code, and it's working fine. Sorry for the bother.

jonsterling commented 12 years ago

No problem! Please let us know if the problem comes back up! Incidentally, the app you are working on looks sweet…