views:

464

answers:

5

Hi, I want to build a Cocoa App with a list of entries very similar to the ToDo list of Things.app (see the screencast). The question is whether I should use

  1. a TableView,
  2. a CollectionView or
  3. a WebView.

I think it could work with all of them, but which one suits the following requirements best?

  • have a list of entries -> 1 column & many rows
  • reordering with drag & drop
  • select single entries & use keys for actions like delete
  • open up an entry: the row should expand to show more input fields
  • customized look: rounded corners, shadow, background gradient

So far my research says that the TableView has most of the functionality, but is harder to customize in its appearance, the CollectionView doesn't have drag & drop (right?) but is easy to design and the WebView would take much effort to not hurt the user experience and I can't bind my model directly to input fields.

What pros and cons am I missing and what would you recommend to use?

+3  A: 

A WebView doesn't make sense. You might as well create a web application if you use a WebView. An NSCollectionView is more for grid like data, like TV listings per hour.

NSTableView is the only one that makes sense in this case. I've implemented all 5 bullet points with with an NSTableView without issue. You need to extend NSTableView and do some custom drawing for the customized look. That's the hardest part.

Matthieu Cormier
+2  A: 
  • open up an entry: the row should expand to show more input fields

You need an outline view. A table view is for flat lists.

Note that NSOutlineView is a subclass of NSTableView, so all the table-view features work on an outline view as well.

Peter Hosey
Hm, doesn't expanding a row in a NSOutlineView just reveal more "subrows"? I'd rather want to change the rows height and put more stuff into it. Does this make sense?
Christian
Yeah. You might actually use a table view, and implement the `tableView:heightForRow:` delegate method they added support for in Tiger: http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/tableView:heightOfRow:
Peter Hosey
You'll also need a custom cell that you can toggle between the different expansion states.
Peter Hosey
+2  A: 

There are people who've done this already. One that I've used successfully is by Matteo Bertozzi and is available here: http://th30z.netsons.org/2009/03/cocoa-sidebar-with-badges-take-2/ It might take a bit of massaging to get it to work properly (especially if you need complex drag-and-drop behavior), but for basic functionality, such as getting the section titles and items in the list, it works excellently.

Edit: This has come up before and is a common question on the cocoa-dev email list. Here are some other options.

Dave DeLong
Those are good resources but I don't think the Sidebar is what we're talking about here. It's the "main content view" part of Things, where the actual todos live.
jbrennan
@jbrennan touché. I started watching the linked screencast, saw the sidebar, and assumed that's what he was wanting. You could technically implement it w/ any of the options he asked in the question. I think I should read the question fully before answering, eh? :)
Dave DeLong
A: 

I'm approaching the very same problem in my app (with one big list similar to the Things todo list) and I think a table view would make a lot of sense here.

The trick is having your cells ("rows") expand when double-clicked. That's about all the progress I've made so far.

jbrennan
How did you get the expanding on double click working?
Christian
Sadly I haven't quite got that working quite yet! So I could be wrong... I'm much more experienced with Cocoa-touch than Cocoa, presently.
jbrennan
+1  A: 

Just took a look at Things.app itself using "F-script anywhere".

They've used a subclass of NSTableView called "DetailTableView" which presents the condensed todo items. Collapsed todo items are implemented using a custom cell called "ToDoCell", but the expanded look you get when editing is interesting. In that case they've got a custom view called "ToDoEditView" which is inserted as a subview of the DetailTableView when required. I suspect this editing view is temporarily added as a subview in the correct location and the corresponding row of the tableview gets resized temporarily while it is present.

All pretty speculative .. I'd love to know the details of how this was done. It's an awesome UI.

Ira Cooke
Good detective work. I'd forgotten about F-Script. Also good to check out is class-dump. And why not check out the Resources folder of the app bundle too, to look at its nibs. These are all things which have helped me in the past.
jbrennan
Yeah .. worth doing all of the above with regard to Things .. for inspiration as it's such a well designed app. Also .. I think the requirement "opening up a row" might best be implemented using the "insert a view" approach used by Things because this would give you a great deal of flexibility if you could get it to work. Obviously the trick (as jbrennan points out) is getting the row to expand to make room for the detail view. I don't have any experience actually trying this out though.
Ira Cooke