You do not allocate outlets. Outlets point to instances in your nib. These instances are instantiated(/allocated) when the nib is loaded. You usually set the File's Owner to be a your own subclass of NSWindowController. Next control-drag from the File's Owner icon to the window and the view to connect the outlets. (Btw, you can probably better use the window outlet from the NSWindowController instead of your spriteWindow outlet, though the latter may be needed if you manage multiple related windows with one controller.)

You create your controller with this:
spriteController = [[SpriteController alloc] initWithWindowNibName:@"YourNib"];

and to show the window you use:
[[spriteController window] makeKeyAndOrderFront:self];
or
[[spriteController spriteWindow] makeKeyAndOrderFront:self];

The drawRect: method of your SpriteView will get called automatically. You do not need to do this yourself. You can force a view to update its drawing using the method setNeedsDisplay:.

Btw, this:
[self setSpriteView: [[SpriteView alloc] init]];

will cause you to leak memory. Use this pattern:
SpriteView *mySpriteView = [SpriteView alloc] init];
[self setSpriteView: mySpriteView];
[mySpriteView release];

thought it should be noted that this is an uncommon way to instantiate a view. (Usually done in nibs, and through the initWithFrame: method, after which it is added as a subview to another view.)

Hth,

Johan

Op 24 jun 2008, om 14:17 heeft Joseph Ayers het volgende geschreven:

I am quite confounded with regard to how/when to allocate outlets which are classes existing as instances in
another class. Consider

@interface SpriteController : NSWindowController {
 IBOutlet  SpriteView* spriteView;
 IBOutlet  NSWindow* spriteWindow;
}

SpriteController* spriteController;

- (id)spriteWindow;
- (id)spriteView;
-(void)setSpriteView:(SpriteView*)view;
}

SpriteView is defined in another subclass as:

@interface SpriteView: NSView
{
 NSImage      *spriteImage;
}

SpriteController and SpriteView are defined and connected in the NIB

When I open the NIB with

-(void)loadSpriteController{
 if (spriteController == NULL) {
     spriteController = [[SpriteController alloc] init];
if (![NSBundle loadNibNamed:@"spriteWindow" owner:spriteController]) {
          NSLog(@"Error loading SpriteController");}
     else{
          NSLog(@"SpriteController NIB Loaded");               }
 }

}

spriteController gets a pointer, but spriteView is NIL. All subsequent messages to spriteView are
messages to NIL

How/where should I be allocating spriteView. I've tried adding:

 [self setSpriteView: [[SpriteView alloc] init]];

to loadSpriteController with no consequence. spriteView gets a pointer but

[[spriteController spriteView] drawRect:[[spriteController spriteWindow] bounds]];
does not get to drawRect

ja


--
Joseph Ayers, Professor
Department of Biology and
Marine Science Center
Northeastern University
East Point, Nahant, MA 01908
Phone (781) 581-7370 x309(office), x335(lab)
Cellular (617) 755-7523, FAX: (781) 581-6076 Boston Office 444RI, (617) 373-4044
eMail: [EMAIL PROTECTED]
http://www.neurotechnology.neu.edu/

_______________________________________________

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/johankool%40gmail.com

This email sent to [EMAIL PROTECTED]

---
http://www.johankool.nl/




_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to