Hey guys/gals,
I have been going even further into cocoa programming and trying to get a calculator program to work (sounds simple, I know). I have a few questions for you:
1- I have hooked up several buttons to a single button handler. In debugging into the code, I can see that my handler gets called for all of the button presses. Now the question is how to detect which of the buttons was clicked? I see that I get a single parameter to the button handler "(id) sender". Just how do I use the sender parameter to determine the button that triggered the event?
2- I have an NSTextView to allow the user to directly type the numbers for the calculations. I need to filter on the keys to only allow certain key events to actually affect the displayed text. More correctly, I need to filter keys, and take on of the following actions:
a. If it's a number, append it to the number in the display, and update the display.
b. If it's an operator, process the operator and reset the display.
c. If it's not one of those, then ignore it.
So how do I do this type of thing? Perhaps, upon thinking about it, it's not really NSTextView that I need, but rather a similarly-displayed label with a border around it.
3- How do I interpret key presses on the window itself, rather than forcing the user to type into a text field? Or, if I switch away from using a text field, how do I intercept key presses for the window itself so I can process them? If I get a key press for the number "1", can I force the button to look like it's been clicked?
4- I imagine much of my terminology is wrong in how I'm using it now that I'm coding in the mac world. Feel free to tell me what terms I should use differently so I can catch up with you all and not appear to be as much of a noob as I really am on the mac front.
Thanks very much to all of you!
Kevin
I have been going even further into cocoa programming and trying to get a calculator program to work (sounds simple, I know). I have a few questions for you:
1- I have hooked up several buttons to a single button handler. In debugging into the code, I can see that my handler gets called for all of the button presses. Now the question is how to detect which of the buttons was clicked? I see that I get a single parameter to the button handler "(id) sender". Just how do I use the sender parameter to determine the button that triggered the event?
2- I have an NSTextView to allow the user to directly type the numbers for the calculations. I need to filter on the keys to only allow certain key events to actually affect the displayed text. More correctly, I need to filter keys, and take on of the following actions:
a. If it's a number, append it to the number in the display, and update the display.
b. If it's an operator, process the operator and reset the display.
c. If it's not one of those, then ignore it.
So how do I do this type of thing? Perhaps, upon thinking about it, it's not really NSTextView that I need, but rather a similarly-displayed label with a border around it.
3- How do I interpret key presses on the window itself, rather than forcing the user to type into a text field? Or, if I switch away from using a text field, how do I intercept key presses for the window itself so I can process them? If I get a key press for the number "1", can I force the button to look like it's been clicked?
4- I imagine much of my terminology is wrong in how I'm using it now that I'm coding in the mac world. Feel free to tell me what terms I should use differently so I can catch up with you all and not appear to be as much of a noob as I really am on the mac front.
Thanks very much to all of you!
Kevin