绑定到 NSMatrix 以获得 BOOL 属性

发布于 2024-10-15 18:15:49 字数 532 浏览 1 评论 0原文

我有一个简单的核心数据实体,它有一个名为 subscribedToNewsletter 的布尔属性。我设计了我的 UI,将此字段表示为单选按钮组,其中 Yes/No 作为文本值(显然 YES/NO 作为支持 BOOL 值)。

我一直认为自己拥有出色的谷歌功能,但在我的一生中,我无法找到任何明确的文档:

  • 如何将 NSMatrix 的选定值(或者是单元格?)绑定回 YES /NO value
  • 如何绑定文本值(如果我确实需要的话;我知道只会有两个值 - 当然它们可以在 Interface Builder 中硬编码,或者不是?)

接下来将是如何将单选组(带有 Male/Female 文本)绑定到名为 gender 的字符串字段,该字段具有 MF作为可能的值 - 但我离题了。

任何指示将不胜感激。多谢。

I have a simple core-data entity that has a Boolean attribute called subscribedToNewsletter. I have designed my UI to represent this field as a radio button group with Yes/No as the text values (and obviously YES/NO as the backing BOOL values).

I have always considered myself to have excellent google-fu, but for the life of me, I am unable to find any clear documentation on:

  • how to bind the selected value of the NSMatrix (or is it the cell?) back to a YES/NO value
  • how to bind the textual values (if indeed I do need to; I know there are only ever going to be two values - surely they can be hard-coded in Interface Builder, or not?)

Next up will be how to bind a radio group (with Male/Female text) to a String field called gender that has M and F as possible values - but I digress.

Any pointers would be very much appreciated. Thanks a lot.

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

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

发布评论

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

评论(2

末蓝 2024-10-22 18:15:49

不确定我是否没有得到答案,因为a)这是一个愚蠢的问题,或者b)世界上没有人知道怎么做。后者对我来说不太可能,所以我只能假设第一个:)

无论如何,以防万一其他人像我一样愚蠢,我想我会就我如何实现它提供一些反馈。

在 Interface Builder 中,我创建了一个 NSMatrix,其中包含两个单选按钮单元格,其中每个单元格的文本分别为“是”和“否”。在属性检查器 (command-1) 中,确保“是”按钮单元的“标签”字段设置为 1,“否”按钮单元的“标签”字段设置为 0。然后,在绑定检查器 (command-4) 中,将矩阵 的 SelectedTag 字段绑定到实体上的布尔属性。简单如馅饼。

我并不声称这是最好的方法......只是它是有效的。

Not sure if I got no answers because a) it is such a stupid question, or b) no-one in the world knows how. The latter doesn't strike me as likely, so I can only presume the first :)

Anyway just in case there others as stupid as me, I thought I'd give some feedback on how I managed to achieve it.

In Interface Builder, I created a NSMatrix with two radio button cells with "Yes" and "No" as the text for each respectively. In the Attributes Inspector (command-1), make sure the Tag field is set to 1 for the "Yes" button cell, and set to 0 for the "No" button cell. Then, in the Bindings Inspector (command-4) bind the SelectedTag field for the matrix to the Boolean property on your entity. Easy as pie.

I make no claims that this is the best way... just that it is effective.

雨轻弹 2024-10-22 18:15:49

我找到了这部分的一个解决方案-

如何绑定选定的值
NSMatrix(或者它是单元格?)回到
是/否值

这是我遇到的问题及其解决方案的链接 - NSMatrix简单的绑定问题

希望这有帮助!

I have found one solution for this part-

how to bind the selected value of the
NSMatrix (or is it the cell?) back to
a YES/NO value

Here is the link to the problem which I faced and its solution- NSMatrix simple binding question

Hope this helps !

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