我试图弄清楚为什么我NSTextFields
只保留在第一种方法sendVarsToButton
中而不是updateTotal
方法中。我需要从第一种方法中设置的 TextField 访问值,但我不能,因为我的 IBOutlets 似乎在sendVarsToButton
方法之后自行释放。你能帮我吗!?
这是我的.h
#import <Cocoa/Cocoa.h>
#import "TransactionViewController.h"
@class TransactionButtonModel;
@interface TransactionButtonController : TransactionViewController
{
NSMutableArray *buttonsArrays;
TransactionViewController *transactionViewController;
TransactionButtonModel *transactionButtonModel;
}
@property(nonatomic,retain) IBOutlet NSTextField *nom;
@property(nonatomic,retain) IBOutlet NSTextField *descriptionText;
@property(nonatomic,retain) IBOutlet NSTextField *prix;
@property(nonatomic,retain) IBOutlet NSTextField *CPUField;
@property(nonatomic,retain) IBOutlet NSTextField *quantite;
@property(nonatomic,retain) IBOutlet NSTextField *total;
-(void)sendVarsToButton:(NSString *)name:(NSString *)description:(double)price:(double)CPU:(long)tag;
-(void)updateTotal:(int)newQuantity;
-(void)addQuantiteToExistingProduct:(long)tag;
-(IBAction)removeProductFromView:(id)sender;
这是我的.m
#import "TransactionButtonController.h"
#import "TransactionViewController.h"
#import "TransactionButtonModel.h"
@implementation TransactionButtonController
@synthesize prix;
@synthesize nom;
@synthesize descriptionText;
@synthesize CPUField;
@synthesize total;
@synthesize quantite;
//In this method, everything works fine
-(void)sendVarsToButton:(NSString *)name :(NSString *)description :(double)price :(double)CPU:(long)tag
{
[nom setTag:tag];
[descriptionText setTag:tag];
[prix setTag:tag];
[CPUField setTag:tag];
[quantite setTag:tag];
[total setTag:tag];
nom.stringValue = name;
descriptionText.stringValue = description;
[prix setDoubleValue : price];
CPUField.doubleValue = CPU;
total.doubleValue = [TransactionButtonModel calculateButtonTotal:quantite.intValue :prix.doubleValue];
NSLog(@"retain! :%lu",[[prix viewWithTag:tag] retainCount]); // returns 2
[transactionButtonModel release];
}
-(void)updateTotal:(int)newQuantity
{
NSLog(@"retain! :%lu",[[prix viewWithTag:2] retainCount]); //returns 0
[total setDoubleValue:[TransactionButtonModel calculateButtonTotal:newQuantity :prix.doubleValue]]; // value of prix = 0 and prix = null
NSLog(@"Updated! :%i",newQuantity);
}
-(void)dealloc
{
[nom release];
[quantite release];
[prix release];
[total release];
[descriptionText release];
}
提前致谢。