views:

604

answers:

2

I'm getting back in to Cocoa development on the Mac after a long stint doing iPhone work. My previous experience with Cocoa on the Mac has just been dinky little tools. I'm looking to build something serious.

Looking at a modern Cocoa application like iPhoto (or Mail or Things or....) many apps use the Single-Window, Source-List based approach. I'm trying to wrap my head around that as best I can because it seems to provide a good experience. However, I'm having a little trouble. Here's how I think it should look, but I'm wondering how others are doing it, and what's really the best way:

  • Starting point of the app is an AppDelegate object which, after launching, creates a Window[Controller?] from a nib, along with setting up its data (from, say CoreData)

  • WindowController loads a window which essentially just has an NSSplitView in it.

  • Left side of the splitview has an NSTableView or NSOutlineView which is set to have the SourceList style.

  • Right side has the main content of the app, depending on which item of the table view is selected.

I would assume somewhere (where?) there are NSViewControllers managing each of the different views which will appear in the right side (think how iPhoto has All Photos, Events, Faces, Places, etc. and I imagine they could all appear in different nibs... is this correct?).

Those view controllers are probably bound to the source list on the left.. how does that work (source list is backed by an NSArrayController of NSViewControllers maybe?).

Anyway, those are my thoughts, am I completely off-base or...? I've looked around the web, found this post here, and I've looked at some Apple source code but I can't seem to wrap my head around it. Any guidance would be welcome.

+3  A: 

One easy way to get a feel for the way nibs are split up is to just go into the iPhoto directory and start opening up nibs

If you want to explore a little more into the class structure you can try browsing around using F-Script

cobbal
I've looked through some of their nibs before, but many of them are older Applications, written before such nice things like NSViewController, so I'm wondering, conceptually, what's the best way to build them given today's technology.
jbrennan
+5  A: 

Breaking the views up into separate nibs is mainly good if you're going to swap out some views for others, since you can load them lazily. And yes, in a modern app, you would use NSViewController, or perhaps KTViewController from KTUIKit (see the posts she co-wrote about NSViewController)

Don't just go running into the arms of the source list, however. A single-window interface can be good for simple apps, but it can quickly become unwieldy when you have many things going on, as they may be better served by breaking them into separate windows; iTunes and Xcode both provide many examples of this (especially the latter, since you can switch it between SWI and MWI).

You need to think about whether a multiple-window or single-window interface would be better for your app. There is no one answer for all apps; it depends entirely on your app, and what you want it to do, and how you want it to look—you (plus the rest of your team, if you have one) are the only one who can answer this question. You may want to do some paper prototyping to do quick experiments in each direction so that you can hold at least fake examples of both UIs up against each other.

Peter Hosey
I've certainly given it lots of thought, and I think it works well for my situation.I think each different view would be different enough to warrant its own nib, but again I'm not sure. When doing iPhone work I rarely used InterfaceBuilder, however with Bindings being so well integrated to it, I think it's time I start using it more. I've also read Cathy's articles, but it's yet another tug in a different direction, hence my confusion on how it should all work.
jbrennan
The real question is not how different the views are, but what you're using them for—what model objects you'll be putting in them. If the two views show different kinds of things, they should be different views, each with its own nib.
Peter Hosey
Right, they'd be different nibs because they are showing different types of things. How would the switching of nibs work? When I select a different row in my Sourcelist, how does that trigger a new nib being loaded in? (Also, should that load a new ViewController, or just swap out the view on the right hand side?)
jbrennan
I believe you would have the source list's `selectedRowIndexes` bound to a property of the window's owner, which would take care of loading the appropriate view controller for the source at the newly-selected index. More specifically than that, I don't know, as I've only ever made multiple-window interfaces.
Peter Hosey