Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: will/didChangeValueForKey: Real World Usage



  I'm not sure how to answer 1 (mmalc?) because it's a rather vague
question and lacking further detail about the design of your
application, it's rather impossible to answer in any useful way. :-}

  I would suggest googling "mmalc bindings" - he's maintained a rather
useful list of examples, I believe two of which demonstrate wiring up
custom views. Perhaps spending time studying those will fit some
pieces together for you.

> 2.  I have heard the warnings against calling -will/
> didChangeValueForKey without "really" changing anything in between.
> Well, consider what happens when the user clicks in an empty part of
> the view with no modifier keys:
>
>      [self willChangeValueForKey:@"selectedTags"] ;
>      [[self selectedIndexSet] removeAllIndexes] ;
>      [self didChangeValueForKey:@"selectedTags"] ;
>
> Now, what if the user clicks there a second time?  The second -
> removeAllIndexes will actually have no effect on selectedTags.  Am I
> disobeying the rule and possibly setting myself up for a crash in
> some future OS version?

  You can avoid this problem by:

1 - Wrapping (with will/did...) the changes in -setSelectedIndexSet:
property of your view.

2 - Creating a "selectNone" or similar method (called when a click
selects nothing, for example) that calls:
  [self setSelectedIndexSet:[NSIndexSet indexSet]];

3 - ONLY modifying the -selectedIndexSet property via
-setSelectedIndexSet: anywhere else in your code.

  This funnels everything through your property accessors and so keeps
everything clean and in one place. Hope that helps.

--
I.S.
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >will/didChangeValueForKey: Real World Usage (From: Jerry Krinock <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.