Re: Problem binding to recreated NSCollectionView
Re: Problem binding to recreated NSCollectionView
- Subject: Re: Problem binding to recreated NSCollectionView
- From: David Carlisle <email@hidden>
- Date: Fri, 16 May 2008 14:18:50 -0600
On May 16, 2008, at 11:03 AM, I. Savant wrote:
On Fri, May 16, 2008 at 12:55 PM, David Carlisle
<email@hidden> wrote:
FWIW, I got my very own collection view (MyVOCV) working nicely with
NSArrayController, all except for animations, and I just pre
ordered the
animation book from Amazon.
So thanks for the suggestions,
Hey! Good work. Maybe it's worth posting on CocoaDev.com or a blog
somewhere. I'm sure a LOT of people would benefit from something like
that. Sort of a "pay it forward" kind of thing. Congrats.
--
I.S.
There are only a few "secrets" involved (in my limited and as yet
unanimated version), and the one about using NSKeyedArchiver is
already on CocoaDev. The other one is that if you bind
MyCollectionView content to NSArrayController arrangedObjects, you
need to have the MyCollectionView content method return a nil to
NSArrayController to force it to call setContent with the updated array.
My MyCollectionViewItem in the nib is connected to MyCollectionView
IBOutlet itemPrototype, and the prototype NSView in the nib is
connected to MyCollectionViewItem IBOutlet prototypeView. When I call
setView in a copy of MyCollectionViewItem, I put that view into a
different NSView variable so as not to confuse it with prototypeView.
These are some important methods in MyCollectionView:
- (NSView *) copyOfPrototypeView {
NSData *d = [NSKeyedArchiver archivedDataWithRootObject:
[itemPrototype prototypeView]];
return [NSKeyedUnarchiver unarchiveObjectWithData:d];
}
- (void) newItemForRepresentedObject:(id)ro {
MyCollectionViewItem *newProto = [itemPrototype copy];
[newProto setCollectionView:self];
[newProto setRepresentedObject:ro];
NSView *newView = [self copyOfPrototypeView];
[newProto setView:newView];
// etc, for example:
[newView setFrameOrigin:p];
[self addSubview:newView];
}
- (void) setContent:(NSArray *)content {
// compare with old content array to do layout and animation
}
- (NSArray *) content {
return nil; // This forces NSArrayController to call setContent
}
- (BOOL) isFlipped {
return YES;
}
// This is probably not needed
- (Class) valueClassForBinding:(NSString *)binding {
return [NSObject class];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden