You must be logged in to post Login Register

Search 

Making a simple sum software

User Post

12:09 am
August 28, 2008


ecstaticax

Member

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


Brandon

Admin

brandontreb

posts 48

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.


About the iCodeBlog forum

Currently Online:

1 Guest

Maximum Online: 7

Forums:

Groups: 2

Forums: 6

Topics: 69

Posts: 254

Members:

There are 138 members

There are 1 guests


Brandon has made 48 posts

Top Posters:

crazyiez - 30

Uhu - 17

Nick - 15

bobcubsfan - 11

Adam - 7

Administrator: Brandon


© - Version 3.1.3 (Build 356)  

Share and Enjoy: