Cocoa Bound NSTableView (or NSOutlineView) Cell for "No Data" - cocoa

Just wondering how I would achieve getting my NSOutlineView (or even a NSTableView) to display a cell (row) based on "no rows" from the Cocoa bound NSArrayController.
At the moment I have an NSOutlineView bound to an NSArrayController (I should really use a NSTreeController, but just playing around.)..
The bindings and working fine in terms of the data being bound (from CoreData). Using various sortDescriptors, it further sorts into alphabetical groups (much like the contacts app)...
When I'm trying to do is get my third cell, the one denoting "no data" / "no entries" to appear when there's nothing from the bindings.
Ay pointers would be handy.
Thanks in advance.
Ade

One solution is an extra view over the outlineview. The view is visible if the number of rows in the array/treecontroller is 0.

Related

In a macOS Cocoa application, How to show only the first 'x' elements that match a NSPredicate in a NSOutlineView populated with a NSTreeController?

I am developing a macOS proof of concept project. I have, in the main window, a NSOutlineView populated with a NSTreeController via Cocoa bindings and Core Data. Under the NSOutlineView, I have a search field and a "Recents" button, a bit like Xcode has in the project navigator. My Core Data model object has a "modifiedAt" property and, when the user selects the "Recents" button, I would like to show only the last 10 modified files in the OutlineView. Any suggestions on how to achieve that ? Thank you in advance for any help.
Set the fetchLimit on your NSFetchRequest to be the number you want (10 in your example).

NSTableView: Renaming one row results in renaming two rows at once

My Setup: I have a cell based NSTableview. The columns are bound to values of an NSArrayController (key-value-binding in Interface Builder). The NSArrayController contains a set of NSManagedObjects (CoreData entity (Device)). The tableview's sortDescriptor is bound the the one of array controller.
My Issue: When I sort the tableview by name and then rename a row, the NSArrayController rearranges it's content and the nstableview changes the order of the rows. I want that. However, instead of just renaming one row, it renames two rows. This only happens if the order of the rows has to change because of its sort descriptor.
I.e. The table view looks like the left row below. If I rename f to b it changes to the row on the right
a -> a
c -> b
d -> b
e -> c
f -> d
I set a breakpoint at the setter of the name property to see what sets the name a second time. However I don't get much smarter by looking at the stack.
This is the first time the setter is being called:
This is the second time:
I have build a sample app, however I cannot reproduce this behavior. I must be doing something wrong somewhere, but I can't find what. Tried everything all day long. Does anyone have an idea, what is going wrong here? Thanks :)
I have found the source of the issue:
I am not sure what the exact reason ist, but there were two rings I did wrong.
I bound the NSTableView's content property the NSArrayController's arrangedObjects. I removed that. That was when I noticed something else must be wrong, since now no data at all has been visible in the NSTableView:
The NSArrayController was not yet ready when the NSTableView was
being setup with the bindings. So the columns have been bound to
nil. I am now binding the column values programmatically to the NSArrayController's arrangedObjects as soon as arrangedObjects is ready.

Is there a concept of viewcontroller containment in NSViewController

In iOS, you have a concept of View Containment, is there such things in OSX?
Basically I want to create multiple nsviewcontroller each managing a specific view. I'd have a MasterViewController with a menu on the left (like ITunes), each time the user click on an item on the left, it would load the correct nsviewcontroller to display it's view.
Any tips to achieve what I need is appreciated
Thanks,
As of OSX 10.10 there is, watch Storyboards and Controllers on OS X.
Comment.
NSViewController did basically nothing (other that load NIBs) for years, I'm glad to see that it finally got from attention. Certain people in the Cocoa crowd here have a snotty attitude about the view controller programming style; I've asked questions like this before and had the "are you a iOS newbie coming to Cocoa" response. That's something that I never understood, it's a great model for containment, and reuse.
The main difference between OS X and iOS is that on an iOS device you have only one "window". On OS X there are desktops that can contain many windows that you can view and interact with at the same time.
In general, it sounds like you are trying to create an NSWindow that contains a single-column NSTableView for your list of choices on the left, and some other view that will display the detail of the selection on the right. It's common to place these within a vertical NSSplitView so the user can adjust their relative widths, but they could also stand on their own, as two separate subviews within the window's main view.
You typically use an NSArrayController to manage the list contents and track which particular item is selected. For your detail view on the right, you would use a single NSView with NSControl subviews that display values bound to the array controller's selected object.
If the data structure varies among your objects, swap in or show/hide various subviews as needed for the different types of data the particular selected object represents. You can use the "Conditionally Sets Hidden" binding option to automatically hide controls for which there is no applicable keyed value.
Alternatively, if there's a fixed number of objects in your list and their structures are all quite different from one another, then you may wish to use a tabless NSTabView that has a separate tab with its own custom view for each of your objects. Observe when the selection changes in your list, and select the appropriate tab accordingly.

View-based NSTableView vs NSCollectionView?

I've understood the fly-weight approach of cell-based NSTableView and I think I understand the differences with NSCollectionView.Differences between (cell-based) NSTableView and NSCollectionView
However, a bit less obvious is the differences between view-based NSTableView and NSCollectionView.
With NSCollectionView's flexibility in displaying its items (i.e. in a grid layout) which could emulate a tableView's list (a grid with maximum one column) and excluding personnal preferences, why would someone choose (View-based) NSTableView over NSCollectionView?
Update: (Recycling of views is implemented since El Capitan)
NSCollectionView doesn't use view recycling. This means that a view will be created for every single collection view item, regardless of whether the view is on screen or not. This can wreck your performance with large data sets. A view based NSTableView uses view recycling and is very efficient, as it recycles a limited number of cells instead of creating new ones for every item. Not to mention that NSCollectionView is overall a poorly written and poorly documented class.

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