获取 NSMatrix 中 NSButtonCell 的当前状态

发布于 2024-08-17 16:09:11 字数 493 浏览 3 评论 0原文

我使用 NSMatrix 作为键盘并调用:

[selectedCell setEnabled:NO];
[selectedCell setTransparent:YES];

当选择一个键时(以防止再次执行相同的操作)。但是,我还希望在完成后“翻转”整个选择的选项 - 即替换所有已删除单元格并隐藏剩余的(未选择)单元格。

是否可以循环遍历矩阵的所有单元格并使用以下内容检查它们的启用/透明状态:

if([selectedCell isEnabled] == NO)
  NSLog(@"the cell is disabled");
if([selectedCell isTransparent] == YES)
  NSLog(@"the cell is transparent");

上面的代码当然不起作用,但你明白了...我是一个相对新手,所以任何非常感谢您的帮助。谢谢 :-)

I'm using an NSMatrix as a keypad and calling:

[selectedCell setEnabled:NO];
[selectedCell setTransparent:YES];

when a key is selected (to prevent the same operation being performed again). However, I'd also like the option of 'flipping' the entire selections when done -- that is, replacing all the deleted cells and hiding the remaining (unselected) ones.

Is it possible to loop through all the cells of my matrix and check their enabled/transparent state using something like:

if([selectedCell isEnabled] == NO)
  NSLog(@"the cell is disabled");
if([selectedCell isTransparent] == YES)
  NSLog(@"the cell is transparent");

The above code doesn't work of course, but you get the idea... I'm a relative newbie, so any help would be much appreciated. Thanks :-)

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

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

发布评论

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

评论(3

时光暖心i 2024-08-24 16:09:11

NSMatrix 让您获得 列数行数,以及 特定行的单元格和列。因此,请在几个 for 循环中执行此操作。

按标签进行操作是可行的,但要求您为每个单元格提供自己的标签,并且(在您显示的示例中)所有标签都在一个系列中。任何奇数、重复标签或未标记的单元格都会导致问题。

NSMatrix lets you get the number of columns and the number of rows, and the cell at a specific row and column. So, do that in a couple of for loops.

Going by tag can work, but requires that you give every cell its own tag, and (in the example you show) that all the tags are in a series. Any odd numbers out, duplicate tags, or untagged cells will cause problems.

温柔女人霸气范 2024-08-24 16:09:11

我使用 NSNumber 来存储单选组的选定索引(在 Interface Builder 中作为 NSMatrix 处理)。为了实现这一点,我合成了一个成员变量,为其设置了单选组的“选定索引”绑定

@interface MyClass {
  NSNumber* m_selectedIndex;
}
@property (readwrite, assign) NSNumber* selectedIndex;

此外,我添加了一个枚举以使值易于理解。

typedef enum { APPLE = 0, PLUM = 1 } SELECTION_STATE;

I use NSNumber to store the selected index of the radio group (handled as NSMatrix in the Interface Builder). To realize this I synthesize a member variable for which I set the "Selected Index" binding of the radio group.

@interface MyClass {
  NSNumber* m_selectedIndex;
}
@property (readwrite, assign) NSNumber* selectedIndex;

Additionally, I added an enum to make values human readable.

typedef enum { APPLE = 0, PLUM = 1 } SELECTION_STATE;
空宴 2024-08-24 16:09:11

更新!!
好吧,伙计们,我已经解决了这个问题:

for(key=1; key <= 16; key++)
if([[numericKeypad cellWithTag:key] isTransparent] == YES)
    // ...or alternatively...
    // if([[numericKeypad cellWithTag:key] isEnabled:NO])
    {
    [[numericKeypad cellWithTag:key] setTransparent:NO];
    [[numericKeypad cellWithTag:key] setEnabled:YES];
    }
else
    {
    //...disable it...
    }

似乎我一直都非常接近,但由于缺乏经验,我花了一整天的时间试图找到正确的语法。无论如何,非常感谢:-)

UPDATE!!
Okay guys, I've solved this with:

for(key=1; key <= 16; key++)
if([[numericKeypad cellWithTag:key] isTransparent] == YES)
    // ...or alternatively...
    // if([[numericKeypad cellWithTag:key] isEnabled:NO])
    {
    [[numericKeypad cellWithTag:key] setTransparent:NO];
    [[numericKeypad cellWithTag:key] setEnabled:YES];
    }
else
    {
    //...disable it...
    }

Seems I was pretty close all along, but I struggled for an entire day trying to find the right syntax due to inexperience. Thanks a lot anyhow :-)

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