• 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: Minimal cocoa application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Minimal cocoa application


  • Subject: Re: Minimal cocoa application
  • From: Andrew Farmer <email@hidden>
  • Date: Thu, 8 Mar 2007 03:43:59 -0800

On 08 Mar 07, at 03:14, Godwin, Mark R wrote:
I'm just getting started with Cocoa, and I've read a fair amount of
"getting started with Cocoa" guides. However, all of these tutorials,
etc., are wrapped up in X code wizards, and Interface Builder generated
stuff. I find this hides all of the nitty-gritty detail that I would
like to understand. I like to know as much as possible what is happening
behind the scenes, before allowing a GUI to hide it away from me.


What I would like to know is, what is the absolute minimum I need to do
to create a window in Cocoa, and fill it with, for instance, a WebView?
Ignoring menu bars and the like to start with.

First of all, I'd suggest you work with Cocoa "normally" for a while. Until you're really familiar with the AppKit runtime, trying to replicate the job that it's doing for you is likely to just frustrate you.


Remember that the primary thing Interface Builder is doing for you is letting you load objects from the .nib file. While it does assist with a bit of the code-writing, most of it is pretty upfront - the only thing it actually does with code is inserting definitions for outlets and stubs for action methods. None of the code it creates is actually functional on its own.

If you're determined to try anyway, I'm not entirely sure how you'd do this (not having attempted this myself), but I believe the key element involved is -[NSWindow setContentView:]. If you can manage to find the right place in your code to allocate a window, all you need to do is allocate a WebView as well and set it as the content view of the window. (This isn't exactly what Interface Builder would create, but it's very similar - Interface Builder would set the WebView up as a subview of a NSView filling the window, so it can coexist with controls.)

I'm assuming this is just a few lines of ObjC code. I tried creating a
NSWindow-derived class...

There are very few situations where it's appropriate to subclass NSWindow. This isn't one of them - subclassing should be reserved for situations where you're trying to extend or override the functionality of an existing class. For example, you might subclass NSWindow if you wanted to provide a class that acted like a window, but used a different visual appearance (ew) or behaved significantly differently (yuck).


The #1 class that you'll end up subclassing in AppKit is likely to be NSView, as that's how you create new views. It's rare that you need to subclass something that is already functional on its own, unless you're trying to create some unusual behavior.
_______________________________________________


Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • RE: Minimal cocoa application
      • From: "Godwin, Mark R" <email@hidden>
References: 
 >Minimal cocoa application (From: "Godwin, Mark R" <email@hidden>)

  • Prev by Date: Re: Minimal cocoa application
  • Next by Date: Re: What Apple technologie should I use to port to MS and U*ix platform ?
  • Previous by thread: Re: Minimal cocoa application
  • Next by thread: RE: Minimal cocoa application
  • Index(es):
    • Date
    • Thread