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

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I am trying to create a calculator in Cocoa. So far, I have the parser ready (made in C++) but my problem lies into building the interface. This is a screenshot of my interface so far (very primitive).
attachment.php


All I want to do is to press a button and have its name appeared into the NSTextField. I could do that by making 10 different functions for each button, but I thought that an NSMatrix would help, so these 10 buttons you see are all NSMatrix.

My question is: How do I take the value of each button pressed in the NSMatrix so that I can display it into the textfield?
(of course there are many ways to do it... but I want to know the way which is more flexible).
 

Attachments

  • Picture 1.png
    Picture 1.png
    10.9 KB · Views: 527

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
Am I creating a memory leak here?

I think I made it, but I think that I am creating a memory leak. Can you check the function that updates the nstextfield? Am I creating a memory leak there?
 

Attachments

  • Calculator test 1.zip
    71.2 KB · Views: 145

kpua

macrumors 6502
Jul 25, 2006
294
0
As far as memory leaks go, you're fine. For reference, here's the line you're referring to:

Code:
[theText setStringValue:[[theText stringValue] stringByAppendingString:[[theMatrix selectedCell] title]]];

You're not using alloc or copy anywhere, so there's no need to use release. All of the strings you're using here are autoreleased or managed by other objects.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.