Skip to content

Instantly share code, notes, and snippets.

@1951FDG
Created October 24, 2013 10:03
Show Gist options
  • Save 1951FDG/1f11a2c7372d714c92ef to your computer and use it in GitHub Desktop.
Save 1951FDG/1f11a2c7372d714c92ef to your computer and use it in GitHub Desktop.
Cocoa window notes
In fact, the two approaches are more or less identical. In the second one, [windowControllers addObject: newWindowController] has the same purpose as [newWindowController retain] in the first one -- to preserve a strong reference to the window controller -- and removeObject/release are similarly equivalent in purpose.
"The flag argument determines whether the window server creates a window device for the new object immediately. If flag is YES, it defers creating the window until the receiver is moved onscreen. All display messages sent to the NSWindow or its NSViews are postponed until the window is created, just before it's moved onscreen. Deferring the creation of the window improves launch time and minimizes the virtual memory load on the window server"
You can set this flag in IB or in code when creating a new window. An easy solution to your problems is probably to make sure that the window is made visible before you draw to it (or that you avoid drawing when it isn't visible), or that you make sure it isn't deferred if you need to draw to it off screen.
Visible at Launch should be unchecked if you want to use -showWindow: to control the timing of that window's visibility.
The behaviour you're seeing is correct since the method initWithWindowNibName: won't actually load the nib. Nib loading happens lazily .. so after you invoke the showWindow method, or some other method such as window that requires the nib to load.
Also, make sure arrayController has been set before you add an observer. Outlets are guaranteed to be set in -awakeFromNib and other methods that are invoked after it: If you’re using a window controller, you can use -windowDidLoad
Unlike the default Interface Builder setup, the prototype view is in its own XIB file. I think that probably deserves its own post.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment