我在學習如何使用一個主數據類爲不同的類設置變量。 在Cocoa中設置不同類中的變量
ClassA的
#import <Foundation/Foundation.h>
@interface ClassA : NSObject {
NSString *stringA;
NSString *stringB;
}
@property (nonatomic, copy) NSString *stringA;
@property (nonatomic, copy) NSString *stringB;
@property (weak) IBOutlet NSTextField *textA;
@property (weak) IBOutlet NSTextField *textB;
- (IBAction)displayStrings:(id)sender;
@end
#import "ClassA.h"
@implementation ClassA
@synthesize stringA, stringB, textA, textB;
- (IBAction)displayStrings:(id)sender {
[textA setStringValue:stringA];
[textB setStringValue:stringB];
}
@end
類X
#import <Foundation/Foundation.h>
@interface ClassX : NSObject {
NSMutableString *stringX;
}
- (void)theVariables:(id)sender;
@end
#import "ClassX.h"
#import "ClassA.h"
@implementation ClassX
- (void)awakeFromNib {
[self theVariables:self];
}
- (void)theVariables:(id)sender {
stringX = [[NSMutableString alloc] init];
ClassA *clssA = [[ClassA alloc] init];
[stringX setString:@"stringX for stringA"];
[clssA setStringA:stringX];
[stringX setString:@"stringX for stringB"];
[clssA setStringB:stringX];
}
@end
沒有錯誤出現在:的我想要做什麼圖,從我的項目中的代碼
這裏的代碼,但是當我運行該程序時,我收到一條關於「無效參數不令人滿意:aString」的錯誤。它看起來像IBOutlet的setStringValue不起作用。有什麼建議麼?
請在您的問題中包含錯誤,並解釋實際結果與預期結果的差異。 – 2012-04-27 19:40:08
@JacquesCousteau更新了我的問題。 – wigging 2012-04-27 19:47:28
該錯誤指向'displayStrings:'內的行嗎? – 2012-04-27 19:50:52