Once again, I am not understanding some aspect of Objective C and/or Cocoa.

I created a simple class that contains two NSTextField objects.  I used IB to 
connect the Controller object with the two text fields.  The code follows.  
This example runs correctly and does copy the value from one text field to the 
other.

#import <Cocoa/Cocoa.h>

@interface Controller : NSObject {
        IBOutlet NSTextField*   textField;
        IBOutlet NSTextField*   copyField;
}

- (IBAction) buttonTarget: (id) sender;

@end

#import "Controller.h"

@implementation Controller

- (IBAction) buttonTarget: (id) sender {
        int     textValue;
        
        textValue = [textField intValue];
        [copyField setIntegerValue:textValue];
}

@end

Now if I extend this to two objects (Controller and View), the resulting code 
does not execute correctly.  Again, I used IB to connect the View object to the 
two text fields.  Using the debugger I find that the two NSTextField objects 
have not been allocated (both have nil values).  The code follows:

#import <Cocoa/Cocoa.h>
#import "View.h"

@interface Controller : NSObject {

        View*   view;
}

- (IBAction) buttonTarget: (id) sender;

@end

#import "Controller.h"
#import "View.h"

@implementation Controller

- (id) init {
        if (self = [super init]) {
                view = [[View alloc] init];
        }
        return self;
}

- (IBAction) buttonTarget: (id) sender {
        [view copyFieldValue];
}

@end

#import <Cocoa/Cocoa.h>

@interface View : NSObject {

        IBOutlet NSTextField*   textField;
        IBOutlet NSTextField*   copyField;
        
}

- (void) copyFieldValue;

@end

#import "View.h"


@implementation View

- (void) copyFieldValue {
        [copyField setIntegerValue:[textField intValue]];
}

@end

I have no idea what I am doing wrong.  Any help would be most appreciated.  
Thanks in advance.

Don Klett

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to