iTopchiyev
  • Home
  • Forum
  • Products
    • FingersTune
    • MySQL Edior Pro
    • Ocarina Pitcher
    • SQLite Editor
    • iCouple
    • Net Reversi
    • PyIde
  • Blog
  • Design
  • About
  • Contact
Home » Blog » Hello iPhone
Oct09 0

Hello iPhone

Here I’m gonna introduce you the paradigm of programming for iPhone using CocoaTouch, Objective C.

The aim is to make a calculator app. By the way, this app is first created for Mac and then ported to iPhone. And that requred just fiew changes. I mean development for both platforms is mostly identical.

Well, I have a

standard program scheme that I use each time I need to test some new for me platform, that’s “Calculator”.

It looks like this:

  1. We have 1 class, let’s call it MYCalculator.
  2. We have 2 classwide available strings: currentVal and previousVal. Theese strings are for storing current and previous values and manipulate them during operations. Both this variables are initialized with “0″ string.
  3. We have an Int32 to store the operator code that we choose by pressing some operator button. Then we’ll use it on Equals button press event. This variable is initiolized with 0 value.

Also we have a Window for storing user interface. And in it:

  1. We have digit buttons 0 – 9.
  2. We have operator buttons +,-,x,/.
  3. We have equals button.
  4. We have clear button.
  5. We have a single read only text box or label or something like that.

In code we have to:

  1. We have a single event processor for digit buttons. It have to get text of sender button and append it to the currentVal string, If currentVal equals “0″ then we simply replace the string by sender text. Then set the text boxs value to currentVals value
  2. And the last we have a single event processor for operation buttons. First we have to check if the last character of previousVal equals to “.” then we have to remove that char. And if operator variable not equals to 5 then we copy the value of currentVal to previousVal. If operator is between 1 ant 4 then we first execute “=” event processor.   It have to get text of sender button and see if it equals to “+” then set the operator variable to 1, if to “-” then 2, if to “x” then to 3, if to “/” then to 4. Then we set the text box value to currentVal value.
  3. We have an event processor for “=” button. First we look at value of operator variable, and if it’s between 1 and 4 including, then according to that value we execute selected operation (1 is +, 2 is -, 3 is x,  4 is /) using currentVal and previousVal and save it to previousVal. Then we set currentVal to “0″ and operator to 5.
  4. We have an event processor for clear button. Here we set all variables (currentVal, previousVal operator) to “0″. Then we set the text box value to currentVal value.

The souce code can be downloaded here

DOWNLOAD NOW
Downloaded 738 times

Note that this X Code project created using PWNed iPhone temlate profile.

No Comments

Trackbacks/Pingbacks

  1. Hello Mac Cocoa « Topchiyev’s Weblog - [...] aim is to make a calculator app. By the way, the project soon ported to iPhone. And that requred ...

Leave a Comment Cancel reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Archives

  • March 2011
  • March 2010
  • January 2010
  • November 2009
  • October 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • October 2008

Apple App Store App Store AppStore blogging Calculator Cocoa CocoaTouch Couple Couples Development Dock Download Event FingersTune FREE Game hello world iCouples IDE ipad iPhone iPhone OS iTunes Mac Net Reversi Objective C PHP Programmers Programming pwned Python Restart Reversi Screencast Screenshot Screenshots Sketches SQL SQLite SQLite Editor Template Top 10 Tutorial update Blog (48)
Design (14)
Development (18)
Products (19)
Uncategorized (1)

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

Recent Comments

  • Jarvis Deuermeyer on Mac OS X Dock Restarter
  • vesselhead on Hello Mac Cocoa
  • Nguyen Huu Hanh Lam on MySQL Editor Pro
  • Vatslav Smirnic on MySQL Editor Pro
  • Topchiyev on Some news about iPhone Python IDE

Latest Discussions

  • Lucky you have a day job in News
  • 5 Things to Know to Before Finding Your [...] in News
  • SQLite Editor crashes all the time on qu [...] in Sqlite Editor

Tweets

  • Steve Jobs gone! I'm crying! :(((((
  • @EFatullayev @NizamiTURK Salam. Maraqlıdır, Azerbaycanlı camaat bu twitterden heç mi istifade etmir? Bizimkiler acaq siyasi söbetler edir?
  • @swiftkck2urdome MySQL Editor

SUPPORT

If you need any support while using the website or any of our products or services to contact us or lieve a feedback use CONTACT FORM or FORUMS.

© 2011 iTopchiyev | Designed by Elegant Themes | Powered by WordPress