> There are two self's, I.e. two different instances. The name 'self' isn't a > single variable. It represents the object that's responding to the message, > and executing the method. > > My guess is that one instance is created in the nib, and the other is > created in code you wrote. > > Use the debugger. Set a breakpoint on the init methods and look at how it > reaches that point.
I'm still trying to hunt down the second instance of 'self' that I'm seeing but I don't understand something here. @interface AppController : NSWindowController { MainViewController *mvc; NSMutableArray *mainViewControllers; } … @implementation AppController - (id) init { ... mainViewControllers = [[NSMutableArray alloc] init]; // This is the 1st and should be only instance I create. mvc = [[DataViewController alloc] initWithController:self]; [mainViewControllers addObject:mvc]; [mvc release]; ... } - (void) awakeFromNib { [self displayViewController:[mainViewControllers objectAtIndex:0]]; } - (void) displayViewController:(MainViewController *) mvc { NSWindow *win = [box window]; BOOL ended = [win makeFirstResponder:win]; if (!ended) { NSBeep(); return; } // This is calling the 2nd instance which I can see w/ the debugger. NSView *mv = [mvc view]; [box setContentView:mv]; } @end When I'm viewing the call stack in the debugger, I see that my DataViewController's init method is called a second time from the line … "NSView *mv = [mvc view]". I'm doing view swapping just as is done in Hillegass's 3rd. ed. book. So my DataViewController is subclassed from a MainViewController which is an NSViewController. I looked at the NSViewController docs but didn't anything about why [NSViewController view] would send an init msg to the receiver. _______________________________________________ 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