Re: Allocating outlets from NIB file
Re: Allocating outlets from NIB file
- Subject: Re: Allocating outlets from NIB file
- From: Chris <email@hidden>
- Date: Tue, 24 Jun 2008 22:49:48 +1000
Hi,
You should not be allocating either SpriteView or SpriteController if
they are referred to in the NIB. (which is the normal case).
Instead you go to the File's Owner object in interface builder, and go
to the Identity tab, and set the Class to be whatever class contains
your loadNib statement. ONLY load the NIB, don't attempt to create
windows, views or controllers. (Let's call this class that loads the
NIB as class "A".). Now you add some outlets to class "A" called
spriteView, spriteWIndow, spriteController or whatever else you need.
Then in interface builder you connect these outlets of "File's Owner"
to those objects. Now when you load the NIB, you'll have pointers to
all the objects you care about in the same object that loaded the NIB.
On 24/06/2008, at 10:17 PM, Joseph Ayers wrote:
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@hidden
http://www.neurotechnology.neu.edu/
_______________________________________________
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
_______________________________________________
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