Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement a customized list in Cocoa?

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?

like image 333
Christian Avatar asked Aug 10 '09 10:08

Christian


4 Answers

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.

like image 191
Matthieu Cormier Avatar answered Nov 12 '22 07:11

Matthieu Cormier


  • 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.

like image 39
Peter Hosey Avatar answered Nov 12 '22 07:11

Peter Hosey


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.

like image 2
Dave DeLong Avatar answered Nov 12 '22 06:11

Dave DeLong


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.

like image 1
Ira Cooke Avatar answered Nov 12 '22 05:11

Ira Cooke