I'm trying to achieve something similar to the Apple Master-Detail pop-up cell example but the bindings don't seem to be working for me.
My app allows users to build up a stageplay; so I have a table view of acts. Each act can have a list of lines so the acts table view drives a second table view of lines (so selecting act one updates the lines table view with the lines of that act).
This setup seems to be working fine.
Each line is of course spoken by a character, so my document object has a list of characters as well as a list of acts. What I want is a pop-up cell in my lines table with values taken from the characters array.
So I followed the steps in that Apple tutorial but it doesn't work...
If I bind the content of the table view column to the CharactersController.arrangedObjects and the selectedObject to LinesController.arrangedObjects.character then the binding works (when I select a value from the pop-up it updates the underlying line object with the new character), but the list shows <Character ...> entries
If I then bind the column's contentValues to CharactersController.arrangedObjects.name then I get the following debug error when I run the app:
2011-03-16 11:28:49.783 ScriptPreparer[5176:903] Cocoa Bindings:
Error setting value <Character: 0x100144f60> of object
<NSPopUpButtonCell: 0x100153ff0> through binding selectedObject
If I remove the selectedObject binding then I still get the <Character...> output in the list.
It seems like the contentValues binding is the broken one. What am I doing wrong?
Here are my bindings:
I discovered what the problem was - I had bindings set on the NSTableView as well as the Table column and the NSPopupButtonCell which was causing strange things to happen.
My conclusion is now that any table bindings not on the table column are WRONG
Related
I have a main NSArrayController bound to an NSTableView with each row containing an instance of MyObject. MyObject has about 30 properties, but the NSTableView only has 5 columns (to show the most important properties). When a row (or more) is selected I have another NSTableView (a detail view) which shows all the properties, one per row. The detail table has two columns, one for the property name and one for the property value.
I have this working right now but my detail NSTableView uses a data source rather than bindings. This works fine as long as I notify my detail controller (which manages the data source) of a change in the main selection so that it can reload the detail table.
While it is easy to detect a change in selection, it is harder to detect a change in one of the properties of a selected object. I see elsewhere on StackOverflow, that one way to do this is to have a dummy property and use keyPathsForValuesAffectingValueForKey. Does this work well performance-wise?
Is there some other/better way to build my detail NSTableView/NSArrayController so that each row represents one property of the selected objects on the main NSTableView/NSArrayController? I'd like to use bindings if possible.
im a osx-dev noob that is trying to build an application with three table views that will show the content of a core data store entity. But each table view is filtered on the attribute "status" of the entity.
the problem occurs when i also want to show the selected entity in textfields. I'm using three different array controllers with different fetch predicates. But in a textfield i can only bind the value to one array controller.
should i ditch the bindings and do it all programaticly or is there a simple solution to this? :)
here is an screenshot so you can grasp my app description.
Keep bindings to populate the text fields if it satisfies what you want to do with this GUI. I'd add an NSObjectController to control the one entity those fields represent. If you want the user's changes to those fields persisted, bindings are still awesome.
But I think with three tables that might control what's displayed in the text fields, you're going to need to have some sort of non-binding glue code that determines which of the tables wins. You can probably do everything you want by implementing some of the NSTableViewDelegate protocol.
If the text fields should display the last entity that the user clicked in any of the tables, simply have each table call the same tableViewSelectionDidChange delegate function. All three tables could have the same delegate. You can then call setContent on the NSObjectController from that function.
You could also use similar glue code to prevent more than one selection in any of the three tables, by having the same delegate function deselect everything in the other tables either through the view or the controller. But that's up to you and needs consideration of whether you want multiple selection, etc.
I'm attempting to use Cocoa bindings to populate an NSTableView using Core Data entities. I've arrived at a point where I'm boggled by the behavior of my application. The array controller is in "Entity Name" mode and is using the my "Song" entity.
The table view I am attempting to load the data into has two columns: one for the song name and another for the artist name (the artist is another entity which has a relationship to a song). Through Interface Builder, I have been able to successfully bind the array controller to the table, and setup bindings for the two columns. However, for some reason, one of the columns' bindings is working perfectly (artist name) while the other is not populating at all (song name).
I have gone through each view in the Document Outline and ensured that both columns are configured in exactly the same manner. I've attached some screenshots below showing the binding setup in Interface Builder.
Binding on the NSTableColumn representing the Song Title
Binding on the NSTextField within the NSTableCellView (the one that is not working)
Binding on the NSTextField for Artist Name (the one that is working)
The final (non-functioning) result
Is there an obvious reason why this approach is not working? Any help would be greatly appreciated. I can also provide any additional information that may be needed to answer this question.
It appears you are using a "view" based NSTableView as opposed to the older "cell" based. Each have a different configuration for bindings. In a view based table view you have to bind the tableview content to the array controllers arrangedObjects (see below), you don't have to deal with the individual column bindings that is for cell based table views.
Your remaining bindings look fine.
Just a wild guess. Since you're speaking of the Song entity.
Can it be that you have to bind the song name to objectValue.song.title?
If 'Artist' isn't just an attribute of the 'Song' entity but an entity itself (which it must likely be if it has a relationship to 'Song') then I think you need to have a separate array controller connected to that column in order for it to work properly.
I am trying a simple application using NSArrayController and cocoa bindings. The application contains - a table with only one column, two buttons "+, -" to add and delete records, two text fields to show count of records entered and sum of these records.
To allow user to enter numbers only, I have assigned NSNumberFormatter to the NSTextField cell.
The model class: "Transaction" contains only one property: "amount". I have used #property and #synthesize to declare and define its accessor methods.
So in all, I want to perform following task:
Allowing user to insert, edit, modify numbers in each row in table.
Displaying count of records entered in a text field.
Displaying aggregate of numbers entered in other text field.
I am able to achieve 1st pt. via cocoa bindings but when I tried to implement 2nd and 3rd pt., it is not working as intended.
I did following things for 2nd and 3rd pt.
for 2nd pt....
1. In binding preference of a text field. I am binding value to array controller.
2. Setting model key path as #count.amount
for 3rd pt....
1. In binding preference of a text field. I am binding value to array controller.
2. Setting model key path as #sum.amount
Can anyone suggest me where I may be wrong or some other way to achieve my requirements??
Thanks,
Miraaj
this problem is resolved now I did following things to resolve it:
Used #count bound to the arrayController's "arrangedObjects"
For the sum part: i. Binded value property of text field to transactions
array controller. ii. Set controller
key as - arrangedObjects iii. Set
model key path as - #sum.amount
cheers.... Miraaj
I've got a table one column of which uses an NSPopUpButtonCell. Try as I might, I can't seem to figure out the way to properly bind everything the way I want it. Here's what I'm trying to do:
I have an NSArrayController plucking items from a managed object context, called 'Field Values'. This is to be used to populate the popup menu for each item (i.e. the list of available choices). I can bind this by selecting the cell in IB and binding its content/objects/values to 'Field Values'.arrangedObjects and 'Field Values'.arrangedObjects.name as appropriate (to get the represented object and the visible title).
I then want to bind the column in such a way that the selected value in each row comes from an array in my controller class, again made visible (and only edited through) another NSArrayController.
So far I've managed to set it up so that every popup menu contains the list of available fields, and that the default value is selected in each of them. Actually selecting an item has no effect, however— it just snaps back to its initial value. I've also managed to find some other variations on this, such as the menu being populated with the selected values, or containing the name of all available values, and the selection containing the -description of the 'none' value I added.
I'm sure I'm missing something fairly simple, but I'm not sure what it is. Presumably there's some subtlety I've missed in how to bind this sort of data (i.e. the Content vs. Content Object vs. Content Value things), but I'm damned if I can see it right now.
Many thanks in advance :o)
I've got a similar set up with a table view, although the data source isn't Core Data based, but I saw one thing you might double check that could be a subtle difference. In my setup for the table column, I have the table column itself bound via content, contentValues, and selectedObject. However, it looks like it's also possible to do the bindings on the actual NSPopUpButtonCell instead. Perhaps it works when the bindings are on the table column, but not when they're on the actual cell? Anyway, there's one thing that might be worth looking into.
Never bind to scroll view, table view or cell.
However, ever bind to table columns.
Watch the title of the Inspector window to be certain of what you're binding.