Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

stadidas

macrumors regular
Original poster
Feb 27, 2006
243
0
Kent, United Kingdom
Hi everyone,

I have recently discovered the joys of NSCollectionView, and have a couple of questions about it.
First of all, is there a way to control how far apart the different views within the collection view are spaced? By default they are crammed together, and short of making each individual view have a transparent padding area, I don't know how to space them apart.
Also, what is the best way to notify the view that it is selected when a user clicks on it? Currently in my modal class I have an "isSelected" boolean variable declared. I have bound my collection view to an array controller named "billsArrayController", and have set up KVO in my controller class to listen for changes to the "selectionIndexes" property. When the selection is changed, I do this:

Code:
for (Bill *bill in bills.billsArray)
	{
		[bill setIsSelected:NO];
	}
	
	if ([[billsArrayController selectedObjects] count] != 0)
	{
		[[[billsArrayController selectedObjects] objectAtIndex:0] setIsSelected:YES];
	}
}
I can then bind the UI controls to the isSelected property to turn them on and off when a bill is selected. However, recording this in the data model just doesn't feel right, and I assume there must be a better way to notify views when their represented object is selected.
Whilst typing this I thought of the idea of overriding the NSResponder becomeFirstResponder and resignFirstResponder methods in my view subclass to alter the view appearance to show selection; would this be a good way to do it?

As always, thanks in advance for any help :) .
 

kpua

macrumors 6502
Jul 25, 2006
294
0
As for the padding/spacing thing, I don't think there's much you can do about that. It seems like NSCollectionView doesn't really allow for much customization at this point.

As for managing selection, see the IconCollection example from Apple.
 

BorgCopyeditor

macrumors newbie
Jan 7, 2009
14
0
First of all, is there a way to control how far apart the different views within the collection view are spaced? By default they are crammed together, and short of making each individual view have a transparent padding area, I don't know how to space them apart.

Have you already tried setMinItemSize:?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Just from a quick glance it doesn't look like it supports something like this. You'd probably have to do it within the view.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.