这是头文件:

@interface calc : NSObject {
    IBOutlet NSTextField *tf1;
    IBOutlet NSTextField *tf2;
    IBOutlet NSTextField *ansr;
    int s;
}

- (IBAction)add:(id)sender;

@end


这是实现文件:

@implementation calc

- (IBAction)add:(id)sender
{
    s = [tf1 intValue] + [tf2 intValue];
    [ansr setStringValue:(@"%@", s)];



}
- (void) dealloc {
    [tf1 release];
    tf1 = nil;
    [tf2 release];
    tf2 = nil;
    [ansr release];
    ansr = nil;
    [super dealloc];
}
@end

最佳答案

s是一个int,而不是一个对象。

试试这个代替:

- (IBAction)add:(id)sender
{
    s = [tf1 intValue] + [tf2 intValue];
    [ansr setIntValue:s];

10-07 16:34