best way to "bind" a collectionview

30 views
Skip to first unread message

Gabe Anzelini

unread,
Sep 30, 2009, 2:44:37 AM9/30/09
to objec...@googlegroups.com
I have a collectionview that is set with an array of objects, what is
the best way to update this collectionview when the objects in the
array change?

Ross Boucher

unread,
Sep 30, 2009, 2:46:25 AM9/30/09
to objec...@googlegroups.com
[collectionView reloadContent];

Trakk

unread,
Oct 2, 2009, 9:25:59 AM10/2/09
to Cappuccino & Objective-J
What I have done, and works, is to use a CPArrayController. Example:

var myCollectionView = [[CPCollectionView alloc]
initWithFrame:CGRectMake(0.0, 0.0, 500.0,500.0)];
[myCollectionView setAutoresizingMask: CPViewWidthSizable |
CPViewHeightSizable];

var cViewItem = [[CPCollectionViewItem alloc] init];
[cViewItem setView:[[ListView alloc] initWithFrame:CGRectMake(0,
0, 200, 200)]] ;
[myCollectionView setItemPrototype:searchResultItem];
[myCollectionView setDelegate: self]; // for handling selections
[myCollectionView setVerticalMargin: 0.0]; // spacing.
[myCollectionView setMinItemSize:CGSizeMake(10.0, 20.0)]; // to
keep it from getting too small
[myCollectionView setMaxItemSize:CGSizeMake(1000.0, 45.0)]; // to
keep it real
[myCollectionView setMaxNumberOfColumns:1]; //setting a single
column will make this appear as a vertical list

_listOfItems = [CPArray array];

arrayController = [[CPArrayController alloc] init];
[arrayController setEditable:YES];
[arrayController setObjectClass:ListItem]; // Declare what the
array holds.
[arrayController setAutomaticallyPreparesContent:YES];
[arrayController setSelectsInsertedObjects:YES];
[arrayController setAvoidsEmptySelection:YES];

[arrayController bind:@"contentArray" toObject:self
withKeyPath:@"_listOfItems" options:nil]; // Bind the array
controller's content array to our _listOFItems array.
[myCollectionView bind:@"content" toObject:arrayController
withKeyPath:@"arrangedObjects" options:nil]; // Bind collection view's
content array to the array controller's arrangedObjects


Then to add items, add them to the array controller. They will then
appear in both the collection view, and the _listOfItems array.
[arrayController addObject:newListItemObject];


Hope this helps... It took me a while to figure this out myself... But
I'm also with a handicap of not knowing Objective-C/J or Coco very
well...
The Bindings objects are mostly in the bindings GIT branch, so, in my
experience, you might need to checkout that branch.

Gabe Anzelini

unread,
Oct 3, 2009, 12:11:09 AM10/3/09
to objec...@googlegroups.com
how does one go about using an addition like this from bindings but
still tracking the master branch for everything else (or is the
binding branch always up to date with master)?

mafis

unread,
Oct 3, 2009, 5:49:50 AM10/3/09
to Cappuccino & Objective-J
That`s a good question. My question is the same.

Miles Tinsley

unread,
Nov 9, 2009, 10:05:31 AM11/9/09
to Cappuccino & Objective-J
You can checkout the bindings branch then merge it back into master
(or jake).

This is what I do to get the benefit of functionality in both
branches. But, of course, you will need to manually do the merge every
so often when the branch is updated.


On Oct 3, 9:49 am, mafis <mafi...@googlemail.com> wrote:
> That`s a good question. My question is the same.
>
> On 3 Okt., 06:11, Gabe Anzelini <m...@gabeanzelini.com> wrote:
>
>
>
> > how does one go about using an addition like this from bindings but
> > still tracking the master branch for everything else (or is the
> >bindingbranch always up to date with master)?
Reply all
Reply to author
Forward
0 new messages