Tuesday, September 23, 2008

4. More detailed informations about subclassing NSView

Either custom Quartz views or OpenGL views, need to subclass abstract class NSView.

In the post 1. Quartz subclassing NSView I explained the two possible methods to achieve this result. My favourite one is the first one, because it is the more reliable and compatible with different versions of Xcode.

Now I just want to note once more the whole procedure visually.

  1. In your project right click on the Classes group and choose Add -> New File....


  2. In the New File chooser windows select Mac OS X.


  3. Then, scroll the upper right scroll view to find Objective-C NSView subclass icon, and select it.


  4. Press Next button.


  5. In the next view, give a name to your class and press Finish button.


  6. Make both Xcode and Interface Builder visible and drag your custom view header from Xcode project window to the NIB window, in Interface Builder. If Interface Builder is not opened yet, double click the MainMenu.xib file, in the Resources group of your Xcode project, to open it.


  7. In Interface Builder, select a custom view instance.


  8. Open Inspector (COMMAND-SHIFT-I), move to the Identity panel and choose your custom view class from the Class drop down menu of Class Identity subsection.



Now the custom view instance, in Interface Builder, is defined as an instance of your custom view class. And you can operate on it editing your custom view class code.

No comments: