How to create a treeview like structure in Nstableview for OSX? - macos

How do I show two records in columns for a nstableview. When clicking on each row I want to expand the nstableview and show some more records under that selected row like a tree view.

Your question is so broad I can only give a broad answer: in Cocoa, what you call a "tree view" is known as an outline view. You can use NSOutlineView to implement it. See the Outline View Programming Topics.

Related

View and Cell based NSTableView

What is the main difference between cell based and view based tableviews in Cocoa.
The understanding I have is cell based tableviews are basically used for displaying strings and view based are for custom cells.User events such as dragging rows, selection etc can be handled in view based.
cell based tableviews use objectValueForTableColumn: method and view based tables use viewForTableColumn: method.
Is my understanding correct?. Or is any other design concerns between these table views. When to go for cell based and when to go for view based.
Thanks in advance
short answer:
A cell can contain only one UI element like a text cell, image view cell, button cell and a few more. The customization ability is quite poor.
A view can contain multiple UI elements as well as other views. The customization ability is almost infinite.
Apple recommends to use always view based table views
NSCell is a lighter weight object and was a solution when it was a concern to have too many NSView objects.
Think more than a decade ago.
Cells are deprecated.
Use views.

Cells don't resize when user resizes NSTableViews columns?

I have found that the text in a table view doesn't grow when the user resizes the column. (Or for that matter shrink if he shrinks the column, because the truncation ellipses then vanish.) Having gathered that this is something to do with constraints, my solution has been to uncheck Use Auto Layout (in the xib's file inspector). Not a big deal, but it comes just when I was beginning to think I might have mastered Autolayout.
Is that really the only way to do this?
The table is view-based, and gets its data from Core Data via an array controller. The text is displayed in an NSTextField.
It is as you have found out yourself.
If you want to know/learn more about NSTableview-behavior search for "TableViewVariableRowHeights" and "TableViewLinks" in Apples documentation and download the samples.
This question appears to be answered in:
How to Expand NSTableCellView Width When Resizing Column in NSTableView
summary: add horizontal constraints to the table view cell
see the link for screenshots

Reordering of NSTableview Rows in View based Tableview

As per apple documentation drag and drop NSTableView delegate methods are called only for cell based TableViews not for View based. So there is no way to do reordering of rows using drag & drop for view based NSTableView?
I have created a small sample project which has an NSOutlineView where you can add and remove items as well as reorder them. This is not an NSTableView but the implementation of the Drag & Drop protocol is basically identical.
I implemented drag and Drop in one go so it's best to look at this commit.
Drag and drop delegate methods get called fine in a view based NSTableView. There is a great presentation from WWDC '11 on view based table views, and it includes a lengthy discussion about drag and drop. Worth watching.
Link here - requires a login.

Which Cocoa control to use to display drill-down table?

Any idea which Cocoa control to use to display the drill-down table as in attached screenshot? On the left panel is a list of items. When an item is selected, the detail of the item is displayed on the right panel. Is it NSOutlineView or NSBrowser? Thanks!
Screenshot http://s1.proxy03.twitpic.com/photos/large/409079140.png
Link to twitpic page
It's an NSTableView on the left, and most likely an NSTextView on the right. The NSTableView on the left most likely has an NSDateFormatter set for the cell in the third column, which handles converting an NSDate object into the NSString value that's shown.
See Table View Programming Guide for more general info on NSTableViews. There is also NSOutlineView, which is a subclass of NSTableView, for when you need to display a data tree. Implementing a table view is much easier than an outline view or NSBrowser, so only go with an outline view if you really need to.
NSOutlineView will produce something like the left panel, but is probably overkill judging by your screenshot.
NSBrowser would give you a Finder-style drill down.
I would personally use two views - an NSTableView on the left and an NSTextView on the right.

Cocoa: How to make table view draw custom views in each cell

I am learning Cocoa and trying to create an application for Mac that displays a simple book list. Each book is an NSView with its cover image, title and author. I want to present this list as a NSTableView with a single column and a book view in each cell. However i can't yet figure out how to display a custom view inside a table cell in interface builder or programmatically. Any tips would be very appreciated :)
Inso.
If all of your "book views" are the same size, why not use NSCollectionView / NSCollectionViewItem? It's a much cleaner solution (provided they're all sized the same).
Assuming a collection view wouldn't be a better solution, what you need to do is to write a custom cell. The column owns exactly one such cell, which the table view will use to draw the column's value for each row.
(If you came from the iPhone, yes, this is completely different from UITableView. Each NSTableColumn has exactly one cell, which it uses for every row.)
If you're using your NSView class somewhere else, then you could make it into a subclass of NSControl and have it use another instance of the same cell class. Like most controls, all the real work would be done by the cell, which enables you to reuse that behavior in multiple controls (your single control and your table view).
See Control and Cell Programming Topics for more info.
Apple added view-based table views in Lion, so you should be able do this natively with NSTableView, now.
(You still can't put an NSView in an NSCell—that wouldn't make sense. But you can have views instead of cells in a table view.)

Resources