Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

Making a simple sum software

User Post

12:09 am
August 28, 2008


ecstaticax

Noob

posts 4

1

Hi. I'd like to make a sum with three text fields and a button.

I've defined a class called “fusebox” containing three outlets called numberField1, numberField2 and answerField, and a class action called calculateAnswer. I connected the object to the outlets and the action to the Fusebox object.

Then I saved the Fusebox class and imported it into project.

This is the code of fusebox.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface Fusebox : NSObject {
    IBOutlet id answerField;
    IBOutlet id numberField1;
    IBOutlet id numberField2;
}
- (IBAction)calculateAnswer;
@end


this is Fusebox.m

#import “Fusebox.h”

@implementation Fusebox
- (IBAction)calculateAnswer {
   
    int num1,num2,answer;
   
    num1 = [numberField1 intValue];
    num2 = [numberField2 intValue];
    answer = num1 + num2;
   
    answerField.text = [NSString stringWithFormat:@"%d", answer];

   
   
}
@end


Here is my problem: I don't know how to associate the sum variable to the answerField.

In Cocoa it would be:

[answerField setIntValue:answer];

but what is the iPhone version?

Thanks in advance, please help me. I'm trying to learn but it's not so easy without a good book to learn from :-(

Gianluca


8:27 am
August 28, 2008


Admin

brandontreb

posts 88

2

Have you tried declaring your answerFields as a UITextField like this

IBOutlet UITextField *answerField;

Once you do this, connect this field in Interface Builder to a UITextField.


I hope that helps.

If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra

Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

4 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.