Re: Binding "hidden" attribute
Re: Binding "hidden" attribute
- Subject: Re: Binding "hidden" attribute
- From: Paul Bruneau <email@hidden>
- Date: Mon, 12 Oct 2009 08:57:52 -0400
Yes, I have recently learned how to do this for my under development
app.
Here is the IB part, pretty straightforward (File's Owner (a
controller class) has a door object with a derived "fake" ivar called
isMonumental:
The tricky part in your case (and mine) is because your "ivar" is not
an ivar but a derived value returned by a method, you need to tell the
KVO system that. Here is my method:
+ (NSSet *)keyPathsForValuesAffectingIsMonumental;
{
return [NSSet setWithObjects:kTypeKey, nil];
}
In your case, you have more than one dependent key, which is fine, try
this (10.5 and later--there's another way for pre 10.5):
+ (NSSet *)keyPathsForValuesAffectingSchemaIsHidden;
{
return [NSSet setWithObjects:@"query", @"source", nil];
}
So now if either of those keys changes, KVO will do something like
notify everyone watching schemaIsHidden (what actually happens is
beyond my knowledge). If you had a "real" BOOL ivar, it would Just
Work without this extra stuff.
You can read all about it here:
https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html
#//apple_ref/doc/uid/20002179
Based on history, there is a good chance I messed something up in this
answer, so I hope someone will correct me if necessary.
On Oct 11, 2009, at 8:34 PM, BareFeet wrote:
OK, let me put this another way:
Has anyone successfully bound the "hidden" attribute of an Interface
object, so that it hides and shows when the ivar changes? If so, how?
Thanks,
Tom
BareFeet
----
From: BareFeet <email@hidden>
Date: 9 October 2009 12:18:38 AM AEDT
To: Cocoa Dev <email@hidden>
Subject: Binding hidden attribute
Hi all,
I'm trying to hide a tab view item according to the value returned
an accessor in my model.
My accessor simply returns YES or NO, as per:
- (BOOL) schemaIsHidden {
return ([type isEqualToString: @"query"] || [type isEqualToString:
@"source"]);
}
In interface builder, in my document nib, I selected the view
belonging to my "Schema" tab view item, set its "Hidden" attribute to:
Bind to: My Array Controller
Controller key: selection
Model Key Path: schemaIsHidden
It compiles OK, but when I run it, I get an error in the log:
Cannot create attributed string from object <null> of class NSNull
What does this mean?
Do I have the correct class (BOOL) returned by my accessor?
My other bindings to this same model and controller work fine.
Thanks,
Tom
BareFeet
_______________________________________________
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