• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSCollectionView - getting notified of selection change?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCollectionView - getting notified of selection change?


  • Subject: Re: NSCollectionView - getting notified of selection change?
  • From: Graham Cox <email@hidden>
  • Date: Mon, 13 Oct 2008 22:02:12 +1100


On 13 Oct 2008, at 9:39 pm, Roland King wrote:

what bothers you about that being KVC-compliant? NSIndexSet is just an immutable object no different from ... NSString. yes it sort of represents a sparse array, but it's just a one-to-one relationship with the NSCollectionView, each NSCollectionView can have a selectionIndexes property and that's one single NSIndexSet. When the selection changes, the entire set changes even if the range it represents changed only by one index.

Well... I'm not sure! Perhaps I was just over-thinking it. On reflection it seems like an ordinary to-one relationship having a setXXX and XXX pattern. Which is how I originally saw it - but then when it didn't work I thought it must be more complicated and so - I guess I talked myself round in circles. Hey-ho.


I thought your addObserver: call looked right and the keyPath: looks right too. Did you try adding NSKeyValueObservingOptionInitial just so you can satisfy yourself you get SOMETHING for that property? What's mutating it? I assume the GUI is and I'd assume that it mutates it in a KVC-compliant manner but ... perhaps it doesn't.


OK, well adding NSKeyValueObservingOptionInitial does indeed invoke the observer, and I get the initial value. But changing the selection doesn't produce any more calls to the same method. The GUI itself is working fine - I click, the selection highlight changes... so something's weird.

Here's the full code:

- (void) awakeFromNib
{
NSAssert( mPickerView != nil, @"expected picker view to be non-nil - check NIB connections");

[mPickerView addObserver:self forKeyPath:@"selectionIndexes" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:NULL];
//[mOKButton setEnabled:NO];
}



- (void) observeValueForKeyPath:(NSString*) keyPath ofObject:(id) object change:(NSDictionary*) change context:(void*) context
{
#pragma unused(context)

NSLog(@"observed change, path = %@, object = %@, change = %@", keyPath, object, change );

if( object == mPickerView )
{
unsigned selCount = [[mPickerView selectionIndexes] count];
[mOKButton setEnabled:selCount > 0];
}
}


Log:

2008-10-13 21:42:51.017 Ortelius[53239:10b] observed change, path = selectionIndexes, object = <NSCollectionView: 0x44d9f0>, change = {
kind = 1;
new = <NSIndexSet: 0x18d0c310>(no indexes);
}




As you can see, all I want is to disable the OK button when there's no selection! Shouldn't be that hard...

(Aside: I've noticed some other glitches with the animation in NSCollectionView (occasionally stuff left unerased) so being a new class it does appear to be a wee bit buggy. Could this be another?)

_______________________________________________

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


  • Follow-Ups:
    • Re: NSCollectionView - getting notified of selection change?
      • From: "Michael Ash" <email@hidden>
    • Re: NSCollectionView - getting notified of selection change?
      • From: Roland King <email@hidden>
References: 
 >NSCollectionView - getting notified of selection change? (From: Graham Cox <email@hidden>)
 >Re: NSCollectionView - getting notified of selection change? (From: Nathan Kinsinger <email@hidden>)
 >Re: NSCollectionView - getting notified of selection change? (From: Graham Cox <email@hidden>)
 >Re: NSCollectionView - getting notified of selection change? (From: Roland King <email@hidden>)

  • Prev by Date: right-click on a title-bar of borderless-window
  • Next by Date: Re: NSCollectionView - getting notified of selection change?
  • Previous by thread: Re: NSCollectionView - getting notified of selection change?
  • Next by thread: Re: NSCollectionView - getting notified of selection change?
  • Index(es):
    • Date
    • Thread