• 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: will/didChangeValueForKey: Real World Usage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: will/didChangeValueForKey: Real World Usage


  • Subject: Re: will/didChangeValueForKey: Real World Usage
  • From: "I. Savant" <email@hidden>
  • Date: Mon, 22 Oct 2007 16:13:31 -0400

  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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: will/didChangeValueForKey: Real World Usage
      • From: Jerry Krinock <email@hidden>
References: 
 >will/didChangeValueForKey: Real World Usage (From: Jerry Krinock <email@hidden>)

  • Prev by Date: will/didChangeValueForKey: Real World Usage
  • Next by Date: Re: detecting when an app is beach-balling
  • Previous by thread: will/didChangeValueForKey: Real World Usage
  • Next by thread: Re: will/didChangeValueForKey: Real World Usage
  • Index(es):
    • Date
    • Thread