• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Connected Objects being allocated
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Connected Objects being allocated


  • Subject: Connected Objects being allocated
  • From: Donald Klett <email@hidden>
  • Date: Fri, 12 Feb 2010 16:31:31 -0500

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Connected Objects being allocated
      • From: Steven Degutis <email@hidden>
    • Re: Connected Objects being allocated
      • From: "Henry McGilton (Boulevardier)" <email@hidden>
  • Prev by Date: Re: Cocoa-based GPS framework?
  • Next by Date: @distinctUnionOfArrays problem
  • Previous by thread: Noon question about Bonjour
  • Next by thread: Re: Connected Objects being allocated
  • Index(es):
    • Date
    • Thread