• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie: Getting an NSWindow and setting its delegate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: Getting an NSWindow and setting its delegate


  • Subject: Re: Newbie: Getting an NSWindow and setting its delegate
  • From: James Spencer <email@hidden>
  • Date: Sat, 30 Jul 2005 09:48:07 -0500


On Jul 30, 2005, at 9:05 AM, Martin Linklater wrote:

1) Try to set the delegate of the default Window which is created when I create the project. Problem is, IB doesn't let me Control- drag from the window to my AppController class. I tried to set the windows delegete in code, but although I can see the 'setDelegate' method for NSWindow in the docs I don't know how to actually get a pointer to the window to begin with... How do you 'find' a pointer to the default NSWindow object that is created with the project ?

As to your second sentence above, assuming that there is an instance of the AppController class showing in the Instances pane of your nib's window, control-drag from the window instance in that pane to the controller rather from the window itself.
As to getting a pointer to the window, you would have to create an IBOutlet in your controller and connect that.


2) Subclass the NSWindow object and use my own window. I've deleted the instance of the standard window from IB, but IB isn't letting me instantiate my own class... It lets me create a subclass of NSWindow and create the source files for it, but the 'Instantiate this class' menu option is greyed out. Why ? I've tried to create an instance of my subclass in the AppController init method (using [[MyWindow alloc] init] ), but that doesn't seem to create anything, and I can't tell why. It's not throwing errors or anything, but it's not creating a window either. I'm puzzled.

This is NOT the way to go (most of the time you should be thinking twice when you start subclassing Cocoa's classes particularly when, as with NSWindow there are delegate methods provided as they usually exist to permit you to modify behavior without subclassing). However, to answer your question "Why?", you don't create instances of subclasses of of Cocoa builtins like NSWindow using "Instantiate this class"; rather, you create a standard NSWindow (too bad you deleted the one you already had) and then in the Inspector for that window, set the Custom Class to be your class.) Now you can manage the object's properties from the Inspector, resize it, place other objects in it, etc. just like a regular window but when the nib is loaded an instance of your custom subclass will be created instead of a normal NSWindow.


As to why you aren't getting a window when you create it in code, there is no way to even give a hint as to why it isn't working without seeing your code but there is more to creating and displaying a window than simply allocating and initializing an instance of NSWindow but again, this is simply not necessary. Go back to 1) above, and connect up the window's delegate outlet to your controller class.

Spence

James P. Spencer
Rochester, MN

email@hidden

"Badges??  We don't need no stinkin badges!"

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Newbie: Getting an NSWindow and setting its delegate (From: Martin Linklater <email@hidden>)

  • Prev by Date: Re: Newbie: Getting an NSWindow and setting its delegate
  • Next by Date: Scanfloat & Locale
  • Previous by thread: Re: Newbie: Getting an NSWindow and setting its delegate
  • Next by thread: Re: Newbie: Getting an NSWindow and setting its delegate
  • Index(es):
    • Date
    • Thread