Re: will/didChangeValueForKey: Real World Usage
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