【问题标题】:Objective C programmatical binding doesn't workObjective C 编程绑定不起作用
【发布时间】:2016-11-11 11:08:36
【问题描述】:

imageView 被正确绑定为 IBOutlet ("imageOKData")。我以编程方式将其可见性(隐藏)绑定到创建绑定时已经可用的自定义对象的 BOOL 属性。

ViewController.m:

- (void)viewDidLoad 
{
[super viewDidLoad];

NSLog(@"Create binding: %hhd",_global.dataFile.imported);    
// --> "Create binding: 0"  

NSDictionary* reverseBool = [NSDictionary dictionaryWithObjectsAndKeys:NSValueTransformerNameBindingOption,NSNegateBooleanTransformerName,
                         nil];  

[_imageOKData bind:@"hidden" toObject:_global.dataFile withKeyPath:@"imported" options:reverseBool];    

}

使用上面的代码,图像应该在viewDidLoad 之后隐藏。但它仍然可见。即使我删除了reverseBool 选项,它仍然存在。我做错了什么?

【问题讨论】:

    标签: objective-c binding


    【解决方案1】:

    这是选项字典。 Jeeeez...我弄错了顺序。应该是

    NSDictionary* reverseBool = [NSDictionary dictionaryWithObjectsAndKeys:NSNegateBooleanTransformerName, NSValueTransformerNameBindingOption,nil]; 
    

    有时你看不到你面前的手。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-20
      相关资源
      最近更新 更多