Re: Is there an NSCollectionView selection change notification?
Re: Is there an NSCollectionView selection change notification?
- Subject: Re: Is there an NSCollectionView selection change notification?
- From: Markus Spoettl <email@hidden>
- Date: Sun, 18 May 2008 22:18:09 -0700
On May 18, 2008, at 8:36 PM, Jens Alfke wrote:
I've started playing with NSCollectionView and everything worked
out beautifully (custom views, selection state handling for items
etc.). One thing I can't figure out is how my application/document
gets notified about a change of selection.
If you bind the collection view to an NSArrayController, you can
observe the controller's selection-related properties, either
programmatically or by using bindings in IB. For example, you can
bind a button's "enabled" property to the controller's "canRemove",
to enable the button only when there's a selection.
Up until now I've tried to stay away from manual KVO, the complexity
of things is overwhelming as it is. However, I have to say it's rather
elegant and works perfectly for this case. Just to be sure I did
things right, this is what I came up with:
@implementation MyCollectionViewController
- (void)dealloc
{
[arrayController removeObserver:self
forKeyPath:@"selectedObjects"];
[super dealloc];
}
-(void)awakeFromNib
{
[arrayController addObserver:self forKeyPath:@"selectedObjects"
options:NSKeyValueObservingOptionNew
context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
// do whatever necessary here
}
Does this look OK, especially, is removeObserver: in dealloc: not too
late?
Thanks for you help!
Regards
Markus
--
__________________________________________
Markus Spoettl
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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