Question

I have a collection view item and its prototype view. Within that prototype view I have a little x button. I want that button to remove the exact collection view item that it is on top of.

I can remove a selected item if I click on the space around the x button but if I go straight to clicking the button before clicking the item it will only erase the last selected item.

ideas?

Was it helpful?

Solution

Alright, this should be fun!

Step one: Change the method signature of removeQuartzPlayer to be:

-(void)removeQuartzPlayer:(id)aPlayer;

Where aPlayer will be the player you want to remove. Change the implementation to look something like this:

[quartzPlayerArrayController removeObject:aPlayer];

Where quartzPlayerArrayController would be replaced with the name of the outlet to the NSArrayController that your collection view is connected to. I'll trust that you can figure out how to create an IBOutlet to it, if you don't already have one.

Step one-point-five: remove the connection between the button and the removeQuartzPlayer method in IB.

Step two: Switch to the Bindings pane of the IB Inspector. Select the "Target" binding and make it look like this:

IB Bindings pane 1

Where the "Controller" popup would be set to whatever object points to your controller.

Step three: Select the "Argument" binding and make it look like this:

IB Bindings pane 2

Where the "Collection View Item" popup... you get the idea.

Step four: Enjoy your new button, brought to you by the (dark) magic of Cocoa Bindings!

Disclaimer: I haven't actually tested this, but since I have a button that does something similar, it should work. Comment away if I've screwed something up.
Billy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top