Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I make an NSWindowController subclass that automatically uses a particular nib file?

0
Posted

How can I make an NSWindowController subclass that automatically uses a particular nib file?

0

An NSWindowController object expects to be told what nib file to load (through its initWithWindowNib… methods), because it is a generic implementation of the default behavior for all window controllers. However, when you write a subclass of NSWindowController, it is almost always designed to control the user interface contained in a particular nib file, and your subclass would not work with a different nib file. It is therefore inconvenient and error-prone for the client of the subclass to have to tell it which nib file to load. This is easily solved by overriding the init method to simply call the superclass’s initWithWindowNibName: method with the correct nib name. Now clients just use init and the controller has the correct nib file. You can also override the initWithWindowNib… methods to log an error, because no clients should ever try to tell your subclass which nib file to use. This is a good idea for any NSWindowController subclass designed to work with a specific nib file.

0

NSWindowController expects to be told by someone else what nib file to load (through its initWithNib… methods), because it is a generic implementation of the default behavior for all window controllers. However, when you write a subclass of NSWindowController it is almost always designed to control the user interface contained in a particular nib file, and your subclass would not work with a different nib file.It is therefore inconvenient and error-prone for the client of the subclass to have to tell it which nib file to load. This is easily solved by overriding the init method to simply call super’s initWithWindowNibName: with the correct nib name. Now clients just use init and the controller has the correct nib. You can also override the initWithNib… methods to log an error, because no clients should ever try to tell your subclass which nib file to use. This is a good idea for any NSWindowController subclass designed to work with a specific nib file. You should only not do this i

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123