I have three NSArrayControllers: one with entities Glyph, where each Glyph has relationship to many to locations. Second with objects Locations with reverse to many relationship glyphs, (they are available values for Glyph.locations). Third has ContentSet set to Glyphs selection.locations. Everything works under MangedObjectContecxt.
Is it possible to bind NSTableView Columns in some way to add/remove location to/from Glyph.locations by clicking NSButtonCell in second column?
You can bind the value of NSButton (checkbox) to show and change a value. If you want something to happen when you click on a NSButton, you have to connect the action.
It is possible to bind the value and observe this value to trigger the action but connecting the action is easier.
Related
I understand that you cannot call view(atColumn:row:makeIfNecssary:) from within tableView(_:heightRow:).
Ideally I'd like to derive height based on a button state within the NSTableCellView. I can think of a couple ways to work around this.
Use objectValue in my custom NSTableCellView to keep track of the state of the button.
Only enable buttons on selected row items and maintain a list of the selected NSTableCellView.
Are these recommended or is there another recommended way to handle this.
Also, is it recommended for a NSTableCellView to know what row/col it belongs too? Or is this something that also should be maintained in objectValue?
My use case is will have a disclosure arrow to expand the cell. I've tested it out and it works, however at this point, I'm using a test flag variable to control the height values not the actual button state.
How to configure a view-based NSTableView to behave like so:
Rows are selectable
The user are unable to trigger edit mode by clicking a cell
Edit mode can be triggered by calling NSTableView-editColumn:row:withEvent:select: programmatically
The table view is dragged from the object library of Xcode interface builder, i.e., it uses an NSTableCellView (with an NSImageView and an NSTextField as its subviews) as the table view's cell view.
For view-based table views, -editColumn:row:withEvent:select: is relatively ineffective. It attempts to make the cell view the first responder for the window, but only certain views will accept first responder status. NSTableCellView does not, because it is not itself editable.
If you want to programmatically initiate editing in the text field within an NSTableCellView, you can do something like:
NSTableCellView* cellView = (NSTableCellView*)[tableView viewAtColumn:col row:row makeIfNecessary:YES];
if ([cellView.textField acceptsFirstResponder])
[cellView.window makeFirstResponder:cellView.textField];
To disable the user from starting editing through the UI, I think you will need to set the text field to not be editable. You would make it editable just before you initiate editing programmatically. For example, add a line cellView.textField.editable = YES; between the above two lines.
Then, you'll want to set it back to non-editable after editing ends. To do this, you can set the delegate of the text field to your controller object and implement -controlTextDidEndEditing:. Or, similarly, you can add an observer of the NSControlTextDidEndEditingNotification notification from the text field. Either way, when your code is called, you set the text field's editable property back to false. (If you don't otherwise have a reference to the text field in question, you can obtain it from the NSNotification's object property.)
I'm wondering if there is a way to use Cocoa bindings to populate a cell-based NSOutineView whose cells are NSButtonCell of a button type, with both images and titles. So, one source of confusion is that I'm trying to provide 2 pieces of information for each cell, an image and a string.
The other thing that confuses me is that normally I think you'd populate a cell-based table by setting the value binding of the NSTableColumn. But if the column's prototype cell is NSButtonCell of a style other than radio button or checkbox, then the value binding disappears.
I came up with something that doesn't exactly answer the question I asked, but comes close enough for my purposes. Instead of using NSButtonCell, I use NSTextFieldCell, and insert the image beside the text as an attachment within an attributed string.
I have a typical Mac CoreData application which displays my entities in an NSTableView with an NSArrayController, and a panel on the right to edit/display the currently selected item in the NSTableView. I have an Entity (Pigeon) with an NSString property (colour) being displayed in an NSComboBox, so that the user can enter their own string for the colour or select a previously chosen colour from the drop down list. This is done by binding the Content Values of the NSComboBox to Pigeons.arrangedObjects.colour. This is sooooooo close to what I want, but because it's an array (and not a set) of all the colours that exist for the pigeons, duplicate values are listed in the drop down list of the NSComboBox. So if for example Blue is entered for the colour for one Pigeon, and it's also selected for a second Pigeon, then Blue is shown in the list twice.
Is there someway, somehow I can filter this to remove duplicate values? I've tried making a second NSArrayController which is bound to the Pigeons.arrangedObjects.colour and setting an NSPredicate to filter it, but I can't seem to figure out an NSPredicate for filtering out duplicate values. I want to use bindings for the values of the colours, so that as the application is running, if a colour is added or deleted (maybe a mistake was made in entering a colour), then the drop down list is updated to only have the currently entered colour values for Pigeons.
What is the best way to not showing these duplicate values?
I am on my phone and a little lazy, but I think you are looking for a keypath that looks like: #"#distinctunionofobects.someproperty"... Or google keypath operators.
I have a list of applications and I'd like to make an NSPopupButton that shows a menu of application names with their icon to the left of each item.
I've been able to bind the NSPopupButton to my array of items, but there isn't a binding entry for an image. I thought I could put a cell in there and bind the cell as an image and as text, but I can't find an appropriate cell in IB.
Is there a clean and simple way to do this using bindings? Do I have to write a custom cell?
There is no way to bind the images as well as the titles of the menu items using a stock NSPopUpButton. You will have to subclass it and write an IBPlugin to expose the subclass. And, of course, you should handle the cell as well.
I've found mixing Bindings with NSPopUpButton to be a bag of hurt for a variety of reasons, including the impossibility of separators and of out-of-model menu items such as “Default” or “All”. Consider using a different control, such as a source list, or populating and re-populating the pop-up menu manually.
NSMenuItem has Image binding (in "Parameters" section waaaaaayyyyy down). So I think that you should bind that value to a path in your array of running applications. You can get an icon for your app using shared NSWorkspace object.