fdh
fdh

Reputation: 5354

How to override NSWindow?

I need to create a custom window, so I have created a subclass of NSWindow. I overode the constructor and a bunch of other functions.

I need to replace the current window with the window subclass I created. I know it has something to do with Interface Builder but have no idea what to do. How would I do this?

I tried removing the NSWindow from the Inspector, and instead adding my custom window, however this only results in no window showing up during runtime.

I also edited the app's delegate to change NSWindow to my custom window and also changed the delegate's "main" outlet to my custom window.

I am on Mac OSX Snowleopard using Xcode 3.2.6

Upvotes: 1

Views: 1164

Answers (2)

ughoavgfhw
ughoavgfhw

Reputation: 39925

First, you need to make sure Interface Builder knows about your custom class. To do this, open your xib file and go to "File->Read Class Files…", and choose your header file.

enter image description here

Then, select the window you want to change and open the inspector. In the last tab of the inspector, under "Class Identity", there is a text field labeled "Class" simply type your class's name here.

enter image description here

After you do this, your custom class will be used as the class for that window. It will look like a normal window in IB, but will let you use custom outlets and actions, and will use your class when you actually run your project.

Upvotes: 2

Christian Schnorr
Christian Schnorr

Reputation: 10786

  1. go to the third tab of the utilities section when your window is selected
  2. enter your custom class name under 'Custom Class'

Upvotes: 0

Related Questions