Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Macgenie

macrumors newbie
Original poster
Jan 8, 2008
14
0
Suffolk, UK
I have an NSMatrix of buttons configured as a regular 0 - 9 keypad.
I have set all the button tags to 0 - 9 - if I were using Interface Builder in the normal way I would instantiate a controller class, connect the keypad and then use the tags to tell my code what button had been pressed.

I have been impressed with the bindings system and I would like to bind my matrix of buttons to an int in my model class but am stumped trying to figure out how to access the key tags through the binding mechanism.

Any help would be appreciated !
 

Macgenie

macrumors newbie
Original poster
Jan 8, 2008
14
0
Suffolk, UK
Reply to Eraserhead

Is this program made in Core Data?

No - I started out with a simple Cocoa application, my main menu nib has an instance of NSController, I have a model class bound to the controller for various text views in the nib (which all work OK).

What I am trying to do is to take the basic calculator app covered in the O'Rielly Cocoa programming book and trying to modify the app to use the bindings system instead of outlets and actions (which were not in use at the time the book was produced).

Once I have learnt how to do this I will be master of the universe (soon)....:)
 

Macgenie

macrumors newbie
Original poster
Jan 8, 2008
14
0
Suffolk, UK
I guess you bind the matrix to the relevant key in the NS Controller...

Thanks Eraserhead, but that's what I've been trying to do!
Every key value I try compiles OK but I get runtime exceptions saying my class is not key-value compliant.

Looking at some of the Cocoa header files & the documentation with XCode I can see a method using :selectedTag - if I could access this somehow via the bindings I might be home & dry.

In the usual way using outlets etc and an instantiated nib class I would have a method containing code such as

- (IBAction)enterdigit:(id)sender
X = (X * 10.0) + [[ sender selectedCell] tag];
[self displayX];

- this takes the value stored in x, shifts the digit left (by multiplying by 10) and then adds in the key stroke to x by referencing the selected cell key's tag (which is set equal to the visible numerical value on each key).

I am trying to replace this code with the bindings system but I can't see how to pass in the tag value of the key - its my setter method that's at fault, I'm sure.

Some examples in the documentation from Apple wouldn't have gone amiss ....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.