Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MDMstudios

macrumors member
Original poster
Mar 18, 2008
36
0
Hello, I am new to cocoa programing, and am trying to develop a simple program that has one button and two NSTextFields, the object of the program is, that once you press the button one of the NSTextFields subtract its value from the other NSTextFields.
I have the compiler saying there aren't any errors, but when I click on the button nothing happens. I have everything in Interface Builder set up right, so I imagine it must be a code problem
Here is the code for it
MyController.h
Code:
#import <Cocoa/Cocoa.h>
@interface MyController : NSObject {
    IBOutlet NSTextField *amount;
    IBOutlet NSTextField *amountToSubtract;
	float myAmount;
	float myAmountToSubtract;

}
- (IBAction)subtract:(id)sender;
@end

MyController.m
Code:
@implementation MyController
- (IBAction)subtract:(id)sender {
	myAmount = [amount floatValue] - [amountToSubtract floatValue]; 
	[amount stringWithFormat:@"%f", myAmount ];
	
}
@end
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I assume the line containing stringWithFormat is you trying to set the value displayed in the NSTextField? If so that ain't gonna work. You need to use one of the setXXXX methods, something like setFloatValue:.

Note that it's not really the Cocoa way to format the string and then set it: use a formatter on the NSTextField instead.
 

MDMstudios

macrumors member
Original poster
Mar 18, 2008
36
0
I assume the line containing stringWithFormat is you trying to set the value displayed in the NSTextField? If so that ain't gonna work. You need to use one of the setXXXX methods, something like setFloatValue:.

Note that it's not really the Cocoa way to format the string and then set it: use a formatter on the NSTextField instead.

Okay thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.