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.
Related
There are a few google results for this question but they are ancient and didn't really help. So I'm asking again for modern uses, how can I set up selection for a single row and column. Like the Numbers app. So the row/column its self is not highlighted but the focus ring is drawn for the row, column that was selected.
I'm open to Cell based or View based implementation. I have tried doing things inside the
- (void)tableViewSelectionDidChange:(NSNotification *)notification
but haven't been able to get things working or looking nice.
Has anyone done this, is there a better view architecture for this?
I created a custom SplitView class that subclasses from NSSplitView. Everything looks right to me, and works fine, except the divider. For some reason it doesn't want to show up between my views of a SplitView.
Any kind of hint or help is highly appreciated!
here is my setup in the nib:
and here how it looks when I run it
interesting thing is, that when I move the mouse to the place where the divider should be, the cursor changes and I'm able to drag it...but for some reason it doesn't look right
You can change the color of the divider using the 'drawDividerInRect:' function to change the color of the divider by passing your own rectangle. It is also possible you moved one of the custom views in the split view and can't see the divider anymore. You could try selecting the different views using the object hierarchy.
I've found that apple doesn't like to make it easy to modify a lot of their different views and controllers, probably because they are trying to maintain some uniformity in the apps that are run on their system.
Is the hidden check box checked?
I am trying to get something like in this screenshot
(source: smokingapples.com)
in cocoa, I mean a custom list control. Do you know how this kind of things can be done?
Thanks in advance for your help,
Regards,
Update:
NSTableView now supports view-based rows with variable heights:
- (NSTableViewRowSizeStyle)rowSizeStyle
Return Value
The row style style. See NSTableViewRowSizeStyle for the supported options.
Discussion
The row size style can be modified on a row by row basis by invoking the delegate method tableView:heightOfRow:, if implemented.
The rowSizeStyle defaults to NSTableViewRowSizeStyleCustom. NSTableViewRowSizeStyleCustom indicates to use the rowHeight of the table, instead of the pre-determined system values.
Generally, rowSizeStyle should always be NSTableViewRowSizeStyleCustom except for "source lists". To implement variable row heights, set the value to NSTableViewRowSizeStyleCustom and implement tableView:heightOfRow: in the delegate.
Availability
Available in OS X v10.7 and later.
Original Answer:
An approach, that's more modern than view hacking NSTableView would be either one of these:
http://github.com/sdegutis/SDListView
SDListView - Clone of NSCollectionView, but with
variable-height items and only using a
single column.
http://github.com/uliwitness/PXListView
PXListView - An optimized list view control for Mac
OS X 10.5 and greater. It was created
after I wrote this post on the
subject.
PXListView is licensed under the New
BSD license.
PXListView uses similar optimizations
as UITableView for the iPhone, by
enqueuing and dequeuing NSViews which
are used to display rows, in order to
keep a low memory footprint when there
are a large number of rows in the
list, yet still allowing each row to
be represented by an NSView, which is
easier than dealing with cells.
The architecture of the control is
based on the list view controls which
are present in both Tweetie (Mac) and
Echofon (Mac).
The project is still very much a work
in progress, and as such no
documentation exists at current.
[Edit: it case it wasn't obvious: the class descriptions seen above are quotations of course ;) Where "I" in the latter one actually refers to "Alex Rozanski", not me.]
This is a simple NSTableView with a redrawn table cell which consists of NSImageView and a fiew customized NSTextFields.
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.
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.