Hi,
In Interface Builder I dragged a push button (NSButton) and a text field (NSTextField) to the window. My aim is to enter a number into the field and print this out to the console by way of NSLog when I push the button. I have an object (not sure if this is the right word) BATester that will control this. The button is connected to BATester as an IBAction called "theButton", and the field as "theField". However my program crashes if I push the button after entering into the field. Can you tell me what is going on? Here are my files:
BATester.h:
BATester.m:
If I push the button first I get an output of [. . .] 0.00000. If I change the field value the output is [. . .] [whatever number I entered]. My program tries to make use of a variable which is part of my object BATester. If there is another way to do this please let me know, but also please tell me what is wrong with the above.
In Interface Builder I dragged a push button (NSButton) and a text field (NSTextField) to the window. My aim is to enter a number into the field and print this out to the console by way of NSLog when I push the button. I have an object (not sure if this is the right word) BATester that will control this. The button is connected to BATester as an IBAction called "theButton", and the field as "theField". However my program crashes if I push the button after entering into the field. Can you tell me what is going on? Here are my files:
BATester.h:
Code:
#import <Cocoa/Cocoa.h>
@interface BATester : NSObject {
NSNumber* numb;
}
- (IBAction)theButton:(id)sender;
- (IBAction)theField:(id)sender;
@end
BATester.m:
Code:
#import "BATester.h"
@implementation BATester
- (IBAction)theButton:(id)sender{
NSLog(@"The button says: %f",[numb floatValue]);
}
- (IBAction)theField:(id)sender{
numb = [NSNumber numberWithFloat:[sender floatValue]];
NSLog(@"The field says: %f",[numb floatValue]);
}
@end
If I push the button first I get an output of [. . .] 0.00000. If I change the field value the output is [. . .] [whatever number I entered]. My program tries to make use of a variable which is part of my object BATester. If there is another way to do this please let me know, but also please tell me what is wrong with the above.