gpt4 book ai didi

objective-c - 不明白Apple的takeFloatValueFrom : Example

转载 作者:行者123 更新时间:2023-12-03 16:40:53 25 4
gpt4 key购买 nike

我不是 iOS 专家,但我对构建应用程序有足够的了解。我了解并理解模式、UIKit 和 Objective-C。我现在正在学习 Mac 开发和这一点 "Cocoa Bindings Programming Topics"让我难住了:

Take as an example a very simple application in which the values in a text field and a slider are kept synchronized. Consider first an implementation that does not use bindings. The text field and slider are connected directly to each other using target-action, where each is the other’s target and the action is takeFloatValueFrom: as shown in Figure 2. (If you do not understand this, you should read Getting Started With Cocoa.)

This example illustrates the dynamism of the Cocoa environment—the values of two user interface objects are kept synchronized without writing any code, even without compiling.

(强调我的)

嗯?不需要开个分店吗?和一个 IBAction 类似

- (IBAction)takeFloatValueFrom:(id)sender {
self.slider.floatValue = [sender floatValue];
self.textField.floatValue = [sender floatValue];
}

这是 Mac 特有的东西吗?如何在不编写任何代码的情况下将两个控件与 XIB 中的目标操作实际连接起来并锁定它们的值?

最佳答案

当您在 Interface Builder 中设置界面时,您可以指定只要另一个对象以某种方式发生更改,它就向另一个对象发送消息。此示例显示的是,您可以将这两个对象连接起来,以便每当 slider 发生变化时,它都会将消息 takeFloatValueFrom: 发送到文本字段,反之亦然。

takeFloatValueFrom:是在 NSControl 上定义的方法,文本字段和 slider 都是 NSControl 的子类。

关于objective-c - 不明白Apple的takeFloatValueFrom : Example,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26287524/

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