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

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?

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.

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.

Related

cocoa nstableview like interface builder

What I'd like to do is basically use a widget like the one in step 4 here:
This is the utilities panel on the right of Interface Builder / XCode, where you can use various Inspector tools, e.g. 'Attributes Inspector', etc.
Does a widget like that exist in Cocoa/Interface Builder? It looks like it's somewhat based on a NSTableView, but I don't see how I'd do the grouping-based functionality using a standard NSTableView (i.e. the 'Show' button on the top-right, or the horizontal line separators between groups), and I also don't quite see how I would do the headers (which span multiple table-rows). The images on top are probably a mix between (visually) a toolbar and (practically) a tab-bar, but it looks like it's integrated in the whole.
I searched somewhat, did see this post, which refers to a non-existing project. I found copies, but they don't appear to work in latest versions of Interface Builder (I'm using XCode 6.1.1). They also appear to be pane/window-based, which is an older version of Interface Builder.
There is no one built-in control to do that. It's a combination of multiple controls, including custom views. Likewise, there are multiple ways to approach implementing it.
There may very well be a tab view to switch out the various inspectors, but, if so, it's "tabless" and the actual buttons to do the switching are customized. There's just a row of buttons and the controller switches the tab view's tab based on which is pressed. If you pick the right button style, set a template image and no title, and set their states so they act like radio buttons (only one "on" at a time), they should draw properly (the selected one will glow blue).
I think it's conceivable that the sections could be implemented using a view-based outline view. It would be a single column and the cells would be the complex views you're seeing. The section headers would be rows at the root level and the sections would be children of those rows, a level deeper in the hierarchy of the outline. Therefore, hiding and showing the sections would be achieved by collapsing and expanding the section header rows. There's even a special view identifier, NSOutlineViewShowHideButtonKey, that NSOutlineView uses to look up a Show/Hide button view from the NIB (or the delegate).
You can also implement the sections and their headers using a stack view. Apple actually has sample code for that exact thing:
InfoBarStackView.

List control in OSX

I need to create a simple list of items on a window in OSX.
Coming from C# background I am looking for a corresponding version of a List ,
A simple control in which all items are added in only one column and vertical order and that's pretty much it. I saw NSTableView in the library but it seems to be a more fancy control with multiple columns like a listview in C#,
Is it the one I need to modify the properties to simplify or is there a simpler control for what I need ?
Thanks,
The NSTableView should be fine for what you want. You can change how it is set up, but usually it just lists things in a single row, vertical format. NSTableView may have more options, but if you just don't use them, everything should be fine.
If there is another reason you don't want to use NSTableView let me know.
Good luck.

Choosing between NSTableView and NSOutlineView

I'd really like to create a table view that is segmented similar to the screen shown ( which is taken from the XCode->Build Phases view ). To be honest, I'm a bit lost on how to start there.
I could use a NSTableView + a custom NSTableCellView that manages the expanding/collapsing behaviour, but I'm entirely not sure if the resizing of an individual row is possible or permitted ( the doc isn't too verbose here ).
The second approach would be to choose a NSOutlineView to accomplish this behaviour, yet it would require some serious subclassing to get where I'd like to go.
So, before I'm doing it wrong again, what would you do? Thanks a lot for your time
– Moritz
I am quite sure that is an NSOutlineView (not sure if is one big outline or 4). The subclassing isn't as hard as it looks. The only item that requires custom drawing is the root element (that's the row with the disclosure triangle.)

How to imitate the workflow view of Automator?

I’m starting to develop my first full-blown Cocoa application containing a view which I would like to behave (and look) similar to Automator’s AMWorkflowView.
The basic features I’d like to achieve:
Positioning of subviews
Display of subviews in expanded / collapsed states
Multiple selection
Drag and drop
In order to get accustomed to Cocoa, I started with a custom NSView which mainly served as a container for the custom subviews and handled their positioning and multiple selection.
The subviews are also subclasses of NSView, and contain a variable amount of views themselves, like buttons, labels and popup menus, and therefore can have different heights.
This worked quite well, but before going on, I want to make sure to have everything neat and tidy according to the MVC pattern.
I suspect that there already is a class in Cocoa that facilitates the implementation of a view container, like maybe NSCollectionView.
It seems that there is no (easy) way to display differently sized views in an NSCollectionView, though. Should I continue implementing my custom NSView (probably using an NSArrayController for selection and sorting support), or are there better ways to go?
Any help is much appreciated
Unfortunately the answer is you'll have to roll your own. NSCollectionView does not allow for variable-sized items (which also rules out expanded/collapsed states).
For a limited number of items, you can accomplish this rather easily (you just need a container view that arranges the subviews properly when asked to layout, then you need to make sure you re-layout when things change). For many subviews, however, you'll need to take care to be as efficient as possible. This can start with laying out as little as possible (only those "after" the resized view, for example) and get as complex as caching a visual representation of a prototype view, drawing the cached images (fast!) for all but the view being edited, and only using/positioning a "real" view for the view being edited.
Drag and drop works the same as it always has, but none of the above accounts for the pretty animation NSCollectionView gives you. :-) It's fast and beautifully-animated precisely because all the subviews are uniform (so the layout calculations are fast and simple). Once you add irregular sizes, the problem becomes significantly more complicated.
The bottom line: If you need variably-sized views, NSCollectionView will not work and you'll need to roll your own or find someone else's shared code, but performance and beautiful animation will not be easy.

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
a TableView,
a CollectionView or
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?
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.
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.
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.
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.
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.

Resources