NSCollectionView View Spacing and Selection Questions

Discussion in 'Mac Programming' started by stadidas, Jan 12, 2009.

  1. stadidas macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #1
    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 :) .
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    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.
     
  3. stadidas thread starter macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
  4. BorgCopyeditor macrumors newbie

    Joined:
    Jan 7, 2009
    #4
    Have you already tried setMinItemSize:?
     
  5. stadidas thread starter macrumors regular

    Joined:
    Feb 27, 2006
    Location:
    Kent, United Kingdom
    #5
    That resizes the individual views to fill at least that size.
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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.
     

Share This Page