NSCollectionView subclassing

  • Hi list,

    I am trying to subclass NSCollectionView using  -
    (NSCollectionViewItem *)newItemForRepresentedObject:(id)object.

    The doc says in this method we have to set the view, representedObject
    and layoutView for the new item. I assume layoutView is the leopard-
    seeds name for collectionView. But I still don't understand how to set
    it in NSCollectionViewItem because there is no setCollectionView
    method. I also did [self setItemPrototype:newItem] and I get an
    infinite loop.

    Thanks.
  • On Nov 9, 2007, at 9:01 AM, <cocoa-dev-request...> wrote:

    > Date: Fri, 9 Nov 2007 16:33:38 +0100
    > From: <public.web...>
    > Subject: NSCollectionView subclassing
    > To: <cocoa-dev...>
    > Message-ID: <4CC4D31F-75A1-4695-99C1-AD735FF8DF82...>
    > Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
    >
    > Hi list,
    >
    > I am trying to subclass NSCollectionView using  -
    > (NSCollectionViewItem *)newItemForRepresentedObject:(id)object.
    >
    > The doc says in this method we have to set the view, representedObject
    > and layoutView for the new item. I assume layoutView is the leopard-
    > seeds name for collectionView. But I still don't understand how to set
    > it in NSCollectionViewItem because there is no setCollectionView
    > method. I also did [self setItemPrototype:newItem] and I get an
    > infinite loop.
    >
    > Thanks.

    As the name implies, the collectionView maintains a collection of
    views. The views come from the collectionViewItems (one to one). Each
    collectionViewItem has a view associated with it.

    If you let the default machinery run, for every model object you feed
    the collection view (its content), you'll get a copy of the
    itemPrototype., including an "copy" of the collectionViewItem's view.

    Your newItemForRepresentedObject should do something like

    NSCollectionViewItem *item = [[NSCollectionViewItem alloc] init];
    [item setRepresentedObject:passedInRepresentedObject];
    [item setView:someNewViewThatWillDisplayDataFromTheRepresentedObject];
    return item;

    File a documentation bug, there's nothing in collectionView or
    collectionViewItem that is named layoutView.

    -----------------------------
    Ronzilla
    Core Bindings/Cocoa Builder/Interface Data
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today