• 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: "Michael Ash" <email@hidden>
  • Date: Mon, 13 Oct 2008 07:42:03 -0400

On Mon, Oct 13, 2008 at 7:02 AM, Graham Cox <email@hidden> wrote:
> - (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];
>        }
> }

I realize this is probably just for testing, but I think it's
important to note that this is not the correct way to write this
method. The correct way is:

- (void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object change:(NSDictionary *)change context:(void
*)context
{
    if (context == <#context#>) {
		<#work#>
	}
	else {
		[super observeValueForKeyPath:keyPath ofObject:object change:change
context:context];
	}
}

(Xcode's autocomplete will helpfully provide you with this stub if you
type "observe" and autocomplete it.) Note that the context you check
against in this method (and thus the context that you provide to the
addObserver: call) must be a guaranteed-unique pointer, which can be
generated by, for example, declaring a static global and taking its
address.

I doubt this is your problem, but getting this one wrong can cause
other subtle problems.

Mike
_______________________________________________

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

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>)
 >Re: NSCollectionView - getting notified of selection change? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSCollectionView - getting notified of selection change?
  • Next by Date: problems with installing appscript as a substitute for NSAppleScript
  • Previous by thread: Re: NSCollectionView - getting notified of selection change?
  • Next by thread: Menu binding displaying serialized NSDictionary rather than specified field
  • Index(es):
    • Date
    • Thread