逻辑是:从视图(3 个文本字段)中读取数据,然后当按下按钮时,将存储在模型中的数据求和并打印出来。
<--头文件-->
#import <Cocoa/Cocoa.h>
@class QuoteAttributes;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *amountOfHardware;
@property (weak) IBOutlet NSTextField *amountOfPrinter;
@property (weak) IBOutlet NSTextField *amountOfSoftware;
@property (strong) QuoteAttributes *quickQuote;
- (IBAction)calculate:(id)sender;
- (void) setValueTotheForm;
@end
请参阅以下代码:
#import "AppDelegate.h"
#import "QuoteAttributes.h"
@implementation AppDelegate
@synthesize amountOfHardware;
@synthesize amountOfPrinter;
@synthesize amountOfSoftware;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
- (void) setValueTotheForm{
[self.quickQuote setNumHardware:[self.amountOfSoftware intValue]];
[self.quickQuote setNumPrinter:[self.amountOfPrinter intValue]];
[self.quickQuote setNumSoftware:[self.amountOfSoftware intValue]];
int totalQuote = [self.quickQuote numHardware] + [self.quickQuote numPrinter] + [self.quickQuote numSoftware];
NSLog(@"%d", totalQuote);
}
- (IBAction)calculate:(id)sender {
[self setValueTotheForm];
}
@end
但是,当我调用此方法时,它会打印0