tags:

views:

215

answers:

3

Hi. 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 :-)

A: 

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 :-)

Bender
+1  A: 

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.

Peter Hosey
Thanks for the tip, Peter. That's a lot cleaner way to do it and also obviates the need to 'hard-wire' the matrix size into the app. Appreciate your feedback!
Bender
A: 

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;
JJD