Xcode Calculator Help

Discussion in 'Mac Programming' started by Nitrex88, Dec 30, 2007.

  1. Nitrex88 macrumors newbie

    Joined:
    Dec 30, 2007
    #1
    Hi, I am fairly new at mac programming, although i have knowledge in many programming languages. I am trying to get into using xcode and to start I thought i would make a calculator with a gui that has buttons to click. The app works fine except for one major problem. Lets say I click the 5 button, the app displays 5 in the above text field, then I can choose an operator, another number such as 7, and display the result in the text field. The problem is that I cant use two digit numbers. If I click 5 and then click 2 to use 52, it wont. It will replace the 5 with the 2. I need a way to use numbers above one digit so when i click 5, it displays 5, and then when i click 2, it displays 52, until I click an operator, in which case it would take the current number in the field and put it in a variable. I am using Xcode 3 in leopard which uses Objective-C 2, if that matters. I dont need sample code if you dont have the time, just an idea of how to do it. Thanks in advance and I hope someone could help
     
  2. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    I suggest you use an NSString to display the number and only turn it into an NSNumber to perform the actual calculation. Then you can just append the new number to the existing string to display it.
     
  3. sord macrumors 6502

    Joined:
    Jun 16, 2004
    #3
  4. Nitrex88 thread starter macrumors newbie

    Joined:
    Dec 30, 2007
    #4
    Thanks for the help

    Thanks for the sample app. That was just what i was looking for. That was really helpful and now i get it. Thanks a lot.
     
  5. Tardigrade macrumors newbie

    Joined:
    May 16, 2008
    Location:
    Sandhurst, UK
    #5
    Hi,

    I'm in the same position as the original poster and could do with the sample app for the calculator if its still available (the link no longer works). Don't know where to start at the moment.

    Thanks in advance.

    Cheers

    Jon
     
  6. Nitrex88 thread starter macrumors newbie

    Joined:
    Dec 30, 2007
    #6
    Here is the link...

    http://www.megaupload.com/?d=M6BUW3NJ

    I couldn't believe it wen i saw a new post on this. It's been like 5 months. Anyway, hope this helps. Also, if you interested in programming you have to check out iPhoneDevCentral.org . Watch my video tutorials under the name Nitrex88 in the intermediate and advanced section and you could learn a lot about cocoa and objective-C in relation to the iPhone. Hope you enjoy!

    Cheers.
     
  7. Tardigrade macrumors newbie

    Joined:
    May 16, 2008
    Location:
    Sandhurst, UK
    #7
    Many thanks. I'll have a look at this over the weekend.

    Kind regards

    Jon
     
  8. GingerSnap macrumors newbie

    Joined:
    Jul 29, 2008
    #8
    I tried to convert the calculator app to iPhone. But it uses NSTextField which is not available on iPhone framework. I tried to use UITextField instead, but it does not have doubleValue, setDoubleValue, stringValue and setStringValue.

    Any help?
     

Share This Page