Re: -[NSView window] returns nil if its NSTabView not selected
Re: -[NSView window] returns nil if its NSTabView not selected
- Subject: Re: -[NSView window] returns nil if its NSTabView not selected
- From: Jim Correia <email@hidden>
- Date: Wed, 7 Jan 2009 23:19:02 -0500
On Jan 7, 2009, at 10:36 PM, Jerry Krinock wrote:
In a view's -awakeFromNib, I often do some initializations which
require the view's -window [1].
This worked fine until I put one of these views inside an
NSTabView. Now, it fails if the tab containing the view is not
selected when the nib is loaded, because in this case -[NSView
window] returns nil. Since I don't see this fact in the
documentation, I made myself a tiny test project [2], and indeed,
that's what happens!
Consider how you might implement something like NSTabView.
One solution might be to hide the unselected views. Another solution
might be to remove the unselected views from the tab view, and
reinsert them as necessary. (In the history of Cocoa, being able to
mark a view as hidden is a relatively recent addition.
Your empirical evidence suggests that NSTabView removes the unselected
views from the view hierarchy.
NSTabView has a delegate which can be used for this purpose. A more
general solution would be to wire up your window requiring code, and
unwiring, in an override of one of these NSView methods:
- (void)viewWillMoveToWindow:(NSWindow *)newWindow;
- (void)viewDidMoveToWindow;
Jim
_______________________________________________
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