Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would one implement a sidebar similar to Mail/iTunes/Finder/etc in Cocoa/IB?

I think the title pretty much says it all... I'm looking to implement an interface similar to the standard OS X sidebar used in all the above mentioned programs, and I'm wondering if anybody has any thoughts as to the easiest way to do it, namely about what view to use for the left hand selection pane. Really I don't think I even need the hierarchical component as seen in the apple apps, I just need a good looking flat list of choices which determine what's shown in the right hand pane.

The obvious start is a vertical split layout view, but beyond that I'm not entirely sure where to go. A collection view with only one column or something like that?

like image 228
Lawrence Johnston Avatar asked Oct 27 '08 21:10

Lawrence Johnston


2 Answers

I've done a few applications that use a similar setup.

I generally use an NSSplitView, with a single column NSTableView in the left pane. Don't forget to disable the headers, and make it display as a "Source View" style.

If you want the disclosure triangles, then you'll want to use NSOutlineView instead of NSTableView, but at least for the first go, I'd stick to a simple NSTableView.

A pattern I also use is to make the NSTableView slightly shorter than the NSSplitView, and have buttons at the bottom (add, delete, etc). I've usually built the program around Core Data, so it's easy to hook up these to methods to create/delete objects, and then bind the NSTableView to the array of objects.

like image 162
Matthew Schinckel Avatar answered Sep 19 '22 19:09

Matthew Schinckel


Direct support for this sort of thing was added in Leopard. It's called a 'source list'.

Please see the AppKit release notes. Search for NSTableViewSelectionHighlightStyleSourceList in the document.

Or, drag out a table view and select Highlight: Source List in Interface Builder.

like image 37
Ken Avatar answered Sep 17 '22 19:09

Ken