• 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
-[NSView window] returns nil if its NSTabView not selected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-[NSView window] returns nil if its NSTabView not selected


  • Subject: -[NSView window] returns nil if its NSTabView not selected
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 7 Jan 2009 19:36:47 -0800

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!

I worked around my immediate problem by defining an outlet and wiring it directly to the window [3], but I can see myself forgetting to do this and having to plow through some mysterious bug every few months from now until eternity.

"When an object receives an awakeFromNib message, it is guaranteed to have all its outlet instance variables set." Is not -window kind of an "outlet instance variable"?

Any better workaround for this?  (-superview doesn't help).

Jerry Krinock

[1] Example: In a subclass of NSOutlineView....

- (void)awakeFromNib ;
    ...
    MyDocument* doc = [[[self window] windowController] document] ;

// Register some observers
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deselectAll:)
name:NSUndoManagerWillUndoChangeNotification
object:[doc undoManager]] ;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deselectAll:)
name:NSUndoManagerWillRedoChangeNotification
object:[doc undoManager]] ;
// Initialize the data source and tell it the
// document from which it can get its content.
BmDataSource* ovds = [[BmDataSource alloc] initWithDoc:doc] ;
...


[2] http://sheepsystems.com/engineering/TabTest.zip

[3] Workaround, in any NSView subclass.

IBOutlet NSWindow* windowWorkaround ;

- (NSWindow*)window {
    NSWindow* window_ = windowWorkaround ;
    if (!window_){
        NSLog(@"Whoops! Connect windowWorkaround outlet in IB for %@",
             [self class]) ;

        // This will work only if our super-NSTabView is selected...
        window_ = [super window] ;
    }
    return window_ ;
}

_______________________________________________

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: -[NSView window] returns nil if its NSTabView not selected
      • From: Quincey Morris <email@hidden>
    • Re: -[NSView window] returns nil if its NSTabView not selected
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: NSScrollView refuses to scroll
  • Next by Date: Re: How to obtain icon displayed by Finder for a file
  • Previous by thread: a kind of auto complete behavior of NSTextview: how to do that?
  • Next by thread: Re: -[NSView window] returns nil if its NSTabView not selected
  • Index(es):
    • Date
    • Thread