开发者

Cocoa bindings -- trying to bind the state of an NSMenuItem to my custom BOOL

开发者 https://www.devze.com 2023-02-08 13:44 出处:网络
In my mac app, [Model m] is a custom object with a synthesized BOOL property and ivar rollAnimations.And animationsItem is an NSMenuItem object.I want to bind the state of my animationsItem to the rol

In my mac app, [Model m] is a custom object with a synthesized BOOL property and ivar rollAnimations. And animationsItem is an NSMenuItem object. I want to bind the state of my animationsItem to the rollAnimations property and ivar of [Model m]. A two-way binding would be ideal (so that changing either property changes the other), but if that's messy (retain cycles and such), I'll settle for a one-way binding, such that changing the menu item changes the rollAnimations property.

Here is a code snippet. It's not working. What am I missing?

NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
NSNumber *yesNumber = [NSNumber numberWithBool:YES];
[bindingOptions setObject:yesNumber forKey:NSValida开发者_运维知识库tesImmediatelyBindingOption];
[animationsItem bind:@"state" toObject:[Model m] withKeyPath:@"rollAnimations" options:bindingOptions];


The Cocoa Bindings Reference lists all the bindings a menu item supports. The one you want is @"value", not @"state". (This goes for buttons, too, by the way.)

0

精彩评论

暂无评论...
验证码 换一张
取 消