Basic Problem reading input from NSTextCell in Xcode

Joined
Oct 22, 2009
Messages
1
Reaction score
0
Points
1
Hi, I'm new to Objective C and just doing some basics.

All I want to do is;

- read a value from one text field
- double it
- output it to another text field

But I'm stuck on the first, each time I try to read the value in it returns a value of 0 even though the entry is clearly 1 or 3 or 100.

This is the snippet

input=[inputfield floatValue];

Where inputfield is the NSTextCell box and input is a float.

The rest of the code is below in case it is useful.

Please help, going insane!

readwrite.m
*******************************************************

#import "readandwrite.h"

@implementation readandwrite

@synthesize input, output;

-(IBAction)calculate: (id) sender
{

// float input;

input=[inputfield floatValue];
self.output=input*2.0;
printf("Input is %f\n",input);
printf("Output is %f\n",output);
[outputfield setFloatValueutput];
}

@end

readandwrite.h
*******************************************************

#import <Cocoa/Cocoa.h>


@interface readandwrite : NSObject {
char input;
float output;
IBOutlet NSTextField *outputfield;
IBOutlet NSTextField *inputfield;


}

@property(readwrite) float output;
@property(readwrite) char input;


-(IBAction)calculateid)sender;

@end
 
Joined
May 2, 2009
Messages
480
Reaction score
13
Points
18
Your Mac's Specs
MBP 2.33 4GB: MacPro 8 Core 2.8, 16GB: MacMini 2.26 4GB: MacMin 2.53 4GB: iPhone3GS 32GB
Hi, welcome to the forums.

I was able to compile and run your code (with a few stylistic modifications) with no issues. I assume you have your outlets and actions correctly setup via InterfaceBuilder and that the calculate message is actually being invoked. Is this correct? I assume your using a simple button control to send the readandwrite target the action and that the connection is made via InterfaceBuilder as well.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top