NSArrayController selection not updating with NSTableView binding - objective-c

This has been befuddling me for hours...
I have an object (CuesDoc) with a property (NSMutableArray *cuesArray) and some other properties. The cues array holds multiple Cue objects. There is a property called (CuesDoc*) currentCuesDoc in my AppDelegate.
In IB, I have an NSArrayController, which is bound to the AppDelegate.currentCuesDoc.cuesArray.
I have a view-based NSTableView which is bound to the NSArrayController and can add/remove/edit values in the table and cuesArray. So far so good.
I have detail fields below that, which are bound to NSArrayController.selection, with the model key path set to each property.
When the view first appears, the detail fields populate with the contents of the first item in the table view, however when I select other rows, the detail fields do not update to reflect the current selection.
I added an observer to selectionIndexes and selection for the NSArrayController, and when the view appears, I get called for the observeValueForKeyPath: method once, but not after changing selections.

For view-based NSTableViews, you must bind the tableView's selection indexes to the array controller key of selectionIndexes to keep the view's selection in sync with the controller's selection. Selection bindings are separate from content bindings. The older, cell-based NSTableView APIs did not require this step.

Related

NSButtonCell in NSCell-based NSTableView & Bindings

I have an NSButtonCell as data cell in one of my NSTableView's columns. The table view is cell-based and has two columns ; one with the button cell, one with a text field cell.
The button cell's respective column's target and argument are bound to my app delegate (as the target) and to the selectedObjects array of an NSArrayController (as the argument).
Basically the same as what's outlined in one of Apple's Technical Q&As.
When I open the app, the table view is automatically populated. Everything works as expected. If I click a button my action method gets called just fine, and this method receives the selectedObjects as a parameter.
It's just not the functionality I want ; I'd like to get the object that is represented by the row of the clicked NSButtonCell instead of the currently selected objects (in my case this is an NSString as my NSArrayController is populated with strings).
Is it possible to get this particular object, only through bindings? Or should I, instead, set the selector of the NSButtonCell (the data cell) without bindings? And then get the object by using NSTableView's -clickedRow method?

NSPopupButton not working in an NSTableview

I have a program using Core Data, with the columns of an NSTableView bound through an NSArrayController. This is working with out an issue, table columns populate without issue. I am expanding the table to include an NSPopupButton - however something odd happens when the button is added. Just dragging the button in to the column, then running the program without connections or binding to the Popup, all the other columns do not populate correctly - they just show the default placeholder text.
Thoughts?
I can get the NSPopupButton to populate, but still the other columns only show the default text. If I remove the NSPopupButton everything works fine.
Why would the other columns have issues? I tried added a CheckBox and had the same issue. I've searched around the net and SO, but have not found an answer.
I would appreciate any thoughts/suggestions.
Thank you in advance.
[EDIT]----
The Table is view-based and NSTableCellView.
arrayController:
Bound to Entity Name
Parameters, bound to Main Controller; key path:managedObjectContext
TableView:
Columns:
Value: Bound to arrayController, key path: name, age, etc...
NSPopupButton:
Value: Bound to Main Controller, Path: catArrayController.arrangedObjects.name
Main Controller:
IBOutlet: catArrayController
Bound to catArrayController in IB
With a view-based table view, you are intended to bind the table view's Content binding to the array controller. You do not bind the columns' Value binding. From Table View Programming Guide for Mac: Populating a Table View Using Cocoa Bindings:
Note: In an NSView-based table, you bind the table view’s content to the array controller’s arrangedObjects. This differs from the technique you use if you’re working with an NSCell-based table.
That binding causes each cell view to have its objectValue property set to the object corresponding to the row, if it has such a property. Note that the cell views don't get a column-specific value. All of the cells of a row get the same value.
Since your cell views are NSTableCellViews, they have an objectValue property. Then, the subviews of the cell view should have their Value binding bound to the cell view with a key path running through objectValue to the specific property (name, age, etc.).
In the old NSCell-based table views, you would typically not bind the Content (or Selection Indexes or Sort Descriptors) bindings of the table view itself at design time. You would bind the table columns as you have done. At run time, the table view would automatically establish bindings for its own Content, Selection Indexes, and Sort Descriptors based on the bindings of its columns. I suspect some version of this behavior was happening in your app which was allowing things to kind of work. However, I suspect that adding the new column broke that system. It was a fluke that it was working for the view-based table view in the first place, so was inherently fragile.

NSArrayController changes doesn't propagate to binded NSUserDefaults

I have a master-detail GUI layout:
NSTableView with content bound to an NSArrayController.
The NSArrayController data is bound to NSUserDefaults rows.
An NSTextField with value bound to the NSArrayController's selection property.
The table is populated with data from the storage as it should, and selecting a row changes the textField value.
Editing the textfield changes the corresponding table row as it should, but it does not change the NSUserDefaults!
If I relaunch the app, the changes are not saved.
BTW, if I add/remove rows from the table - it is persisted, but changes to row data are not.
It seems like the changes in the NSArrayController selection dictionary are not propagated to NSUserDefaults.
What solved the problem finally was checking "Handles Content as Compound Value" in the content binding preferences of the ArrayController.
Screenshot:

Scroll NSTableView to selection

OK, this is my situation :
I have an NSMutableArray bound to an NSTableView, via an NSArrayController.
I'm manipulating the table view's selection (trigger by keyboard), using NSArrayController's selectNext: and selectPrevious:
The thing is : The selection does change, but the table view doesn't scroll to the current selection, so that its content is visible.
What should I do? Any ideas?
There is a method in NSTableView
- (void)scrollRowToVisible:(NSInteger)row;
That will scroll to the specified row.

Retrieving the selected object in an NSOutlineView

I am looking to retrieve the selected object in an NSOutlineView so I can see if the selected object has any children. How would I do this?
NSOutlineView inherits the -selectedRow method from NSTableView. I suspect though, that what you really want is the current selection from whatever NSController is acting as your outline view's data source.