gpt4 book ai didi

objective-c - NSButton 以编程方式列出或解除现有绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 17:09:17 24 4
gpt4 key购买 nike

我使用的是 XCode 9.3、Objective-C、OSX,而​​不是 iOS。

我有一个 NSButton,它在不同情况下以编程方式接收不同的绑定(bind)。

这样想

// Note these values are just for demonstration, in my code they are all dynamic
BOOL requiredState = true;
NSString* state = @"hidden"; // can also be "enabled" or "hidden2"
SomeObject* someObject = [SomeObject new]; // An object that has a value for keyPath key;
NSString* key = @"someValue";

id options = requiredState ? [NSDictionary dictionaryWithObjectsAndKeys:NSNegateBooleanTransformerName, NSValueTransformerNameBindingOption,nil] : nil;

// Bind button
[self.nextButton bind:state toObject:target withKeyPath:key options:options];

在某个时刻我需要解除现有的绑定(bind)。有没有办法从该按钮读取现有的绑定(bind)?或者至少是键,以便我可以枚举它们来解除绑定(bind)?

// Idea
[allBindingKeys enumerateObjectsUsingBlock:^(NSString* key, NSUInteger idx, BOOL * _Nonnull stop) {
[self.nextButton unbind:key];
}]

当然,我可以在绑定(bind)它们时存储所有 key ,只是认为可能有一个更优雅的解决方案。

最佳答案

for(NSString *binding in self.nextButton.exposedBindings)
{
[self.nextButton unbind:binding];
}

关于objective-c - NSButton 以编程方式列出或解除现有绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49797651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com