I need to disable the reordering of rows in a NSTableView so that when I open the application data of the NSTableView are in the same order in which I created them.
In Inspector, check the bindings of the sorted table column, select value and check that the option "Creates Sort Descriptor" in unchecked.
Related
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.
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:
I've got a Core Data application with an NSTableView and the columns are hooked up to an arrayController. Problem is, when I click the tabs at the top of the table to sort the contents nothing happens.
My bindings look like this:
Any idea where I'm going wrong?
Have you selected Create Sort Descriptor on the Value binding for those columns?
Background:
I have a UITableView that displays data from an array. I am utilizing KVO to display an "Edit" button in the navigation bar when the array count is greater than 0 and removes itself when the count is 0. This is working fine. When editing, I place a "Delete" bar button item as the right bar button item. This is also working fine. The Delete button as expected is enabled by default. The table view has multipleSelectionDuringEditing set to YES. I am able to select multiple items and delete them properly. My goal is to enter editing with the Delete button disabled until at least 1 item is selected and subsequently disabled when there are 0 selections. I have tried some things but they have been fruitless. I attempted to have an NSMutableSet property (private) that I could monitor with regards to it's count and appropriately enable/disable the Delete button. However, I have run up against a wall. tableView:DidSelectRowAtIndexPath: is only called on an initial selection during editing, NOT when the row is deselected. Am I overlooking the ability to monitor table selection during editing mode? Thanks in advance.
Additonally, if I were to move the "Delete" button to a UIToolbar with the intention of also including a "Delete All" button, is there a way to select all of the rows (even those not visible)?
According to the docs, calling -indexPathsForSelectedRows on the table view can tell you how many are selected right now, and your delegate's -tableView:didDeselectRowAtIndexPath: should be invoked whenever the user deselects a row.
I don't see a convenient method for programmatically selecting multiple rows. If you're doing a "delete all" command, it might be more appropriate to just delete your underlying model objects and then tell the table to update (that is, not worry about selecting them all first). You can animate that using -deleteRowsAtIndexPaths:withRowAnimation: and/or -deleteSections:withRowAnimation:; either way you'll have to enumerate for yourself which rows/sections you want to delete, but the correspondence between table sections/rows and your collection(s) of model objects should be pretty straightforward, especially since you're nuking everything.
I have a an NSTableView when ever I click on a specific header column the data in the table get reversed or sort upside down. I have checked NSTableView as well as NSTableColumn but couldn't find any method that disables this. I would be obliged if anyone can help in disabling this sorting on clicking on the header of a particular column.
Sorting of the NSTableView is done by its sortDescriptors, see here.
An NSTableColumn uses its sortDescriptorPrototype (see here) to generate the sort descriptor of the NSTableView, depending on how many times you clicked the column header, etc.
If you use dataSource to manage the data, then the sort descriptor is communicated via the delegate method tableView:sortDescriptorsDidChange:, see here. You just need to ignore the change message to stop sorting.
If you use Cocoa bindings to manage the data, the sort descriptor is generated by the table column and set to the NSArrayController. To stop it, just open the inspector of the binding of the table column, select value, and uncheck "Creates Sort Descriptor."