为什么要绑定 NSProgressIndicator 的值?

发布于 2024-10-16 01:17:22 字数 133 浏览 4 评论 0 原文

将 NSProgressIndicator 的值绑定到控制器有什么意义?除了启动时之外,它似乎从未向控制器询问该值。移动 NSProgressIndicator 的唯一方法似乎是发送 #increaseBy:,这会绕过我的绑定。那么,我为什么要绑定?!

What's the point of binding the value of a NSProgressIndicator to your controller? It never seems to ask the controller for the value, except on startup. The only way to move the NSProgressIndicator seems to be by sending it #increaseBy:, which bypasses my binding. So, why would I bind?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海拔太高太耀眼 2024-10-23 01:17:22

如果您的 UI 绑定值未更新,则意味着您绑定失败,或者您的控制器代码未以键值观察兼容的方式修改绑定值。最常见的问题是执行 fooIvar = val 而不是 [self setFooIvar:val]self.fooIvar = val

苹果对您问题的回答:

[如果]以编程方式更改模型属性的值未反映在用户界面中,该怎么办

如果以编程方式对模型值所做的更改未反映在用户界面中,这通常表明模型对象不符合属性的键值观察,或者您正在以以下方式修改值:正在绕过键值观察。您应该确保:

  • 模型类启用了自动键值观察或为属性实现手动键值观察。
  • 您正在使用访问器方法或使用键值编码兼容方法来更改值。直接更改实例变量的值不会提供键值观察更改通知。
  • 如果您的模型属性是集合,则您正在以符合键值观察的方式修改内容。请参阅“我的收集控制器未显示当前数据”了解更多信息。

有关该答案和其他常见问题的解答,请参阅 “对 Cocoa 绑定进行故障排除。”

您还应该查看由mmalc。它们是宝贵的资源。

If your UI's bound value not updating, that means you either bungled the binding or your controller code is not modifying the bound value in a key-value-observing–compliant way. The most common problem is doing fooIvar = val rather than [self setFooIvar:val] or self.fooIvar = val.

Apple's answer to your problem:

[What to do if] Changing the value of a model property programmatically is not reflected in the user interface

If changes made to a model value programmatically are not being reflected in the user interface, this typically indicates that the model object is not key-value-observing compliant for the property, or that you are modifying the value in a manner that is bypassing key-value observing. You should ensure that:

  • The model class has automatic key-value observing enabled or implements manual key-value observing for the property.
  • That you are changing the value using an accessor method, or using a key-value-coding compliant method. Changing the value of an instance variable directly does not provide key-value observing change notifications.
  • If your model property is a collection, that you're modifying the content in a key-value-observing compliant manner. See “My collection controller isn’t displaying the current data” for more information.

For that answer and answers other common problems, see "Troubleshooting Cocoa Bindings."

You should also look at the examples provided by mmalc. They are a valuable resource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文