GeoffCoope
GeoffCoope

Reputation: 962

NSCollectionView Deleting ManagedObject causes NSValueTransformer to run issue

I have an NSCollectionView that shows a grid of prototype items, this is all handled via Core Data, Interface Bindings and an NSValueTransformer to show a placeholder image inside the NSCollectionViewItem if no real image exists.

When I want to delete an item from the NSCollectionView it removes it from the collection view but flashes up my placeholder image (triggered from my NSValueTransformer subclass) for a micro second just before it vanishes from view.

I can not find a way to stop the NSValueTransformer running when it detects that an object in the MOC has been deleted. Why is it even running?

The steps I take are:

for (MyEntityClass * obj in [myArrayController selectedObjects]) {

    [myArrayController removeObject: obj];    // This on its own works fine.
    [managedObjectContext deleteObject: obj]; // This causes a flash

}

If I just delete the object from the MOC (without removing from the arrayController) it flashes the placeholder image for a micro second.

Is there a way to stop the deletion of a MOC object from causing the CollectionView to run the NSValueTransformer before removing it from the view?

I tried adding a delay between ArrayController removeObject and the MOC deleteObject which fixes the flashing of the icon but then causes a Core Data field can not be nil errors if the user deletes a group of items in one go.

Any ideas to stop the placeholder image flashing up just before it removes the object from the collection view?

Upvotes: 0

Views: 115

Answers (1)

GeoffCoope
GeoffCoope

Reputation: 962

Solved it.

The problem was due to saving the managedObjectContext inside the for loop (not shown in sample code above). When the MOC saves it was refreshing the collectionView while it was still removing the object due to the animation which caused the glitch.

Upvotes: 0

Related Questions