Two Very Important Classes: NSWindow and NSView

In this section we’ll describe the very important NSWindow and NSView classes in more detail and list many of their most useful instance methods.

The NSWindow Class

NSWindow is one of the most important classes in the Application Kit. If you want to be an effective Cocoa programmer, it is essential that you be familiar with the variety and scope of NSWindow’s many methods.

Every on-screen window displayed by a program is controlled by an instance object of the NSWindow class. Each NSWindow object receives events from a program’s NSApplication object. Most mouse events are sent to the object within the window where the mouse event took place (e.g., if an on-screen button is clicked, a mouseDown: message is sent to the corresponding NSButton object). Keyboard events are sent to the object that is the window’s first responder, which we’ll describe in detail in the next chapter.

Each window contains at least one instance of the NSView class (described shortly), called the window’s content view . Although you can work directly with a window’s content view, normally you will create subviews of the content view in which you do your actual drawing and event processing. We’ll discuss these ideas in great depth in the following chapters.

Some of the most common instance methods for NSWindow objects are listed in Table 7-4. Recall that if an argument’s data type isn’t specified (e.g., sender), it’s an id by default.

Table 7-4. Common instance ...

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.