NSArrayController , arrangedObjects and tableColumn IB connection - macos

I am new to mac development. I am trying to make this app from apple.com
At one point i am stucked in interface builder.
How do i connect arrangedObjects.firstName to the Value - Table Column - First Name and Last Name?
Edit:
this is my array controller and its bindings.
Thank you in advance..!!

Ctrl Shift click with a mouse on a column in your table (NOT column's header). You should see the list of views which are parent to each other:
Select NSTableColumn view. Then just open bindings tab and perform same procedure as with arrangedObjects' binding.

Related

Binding Core Data Entity to NSTableView: Model Key not working

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.

Sharing NSArrayController Between Nibs

I have an Core Data-based iTunes-like app I'm building that has an NSTableView in the main window and allows the user to select items in the table view and perform a "get info", like in iTunes. Currently I'm working on the single-item get info window, which displays when the user selects a single item in the main window (which is in MainMenu.xib) and pressed Cmd-I. This brings up the single-item get info window (in SingleItemGetInfo.xib).
The table view in the main window is populated via bindings to an NSArrayController. If I put an NSArrayController into the SingleItemGetInfo.xib file, I understand that's going to be a different instance of NSArrayController.
So, what's the proper way to bind the fields in the single item get info window to the selection the user has made in the main window's table view?
MainMenu.xib's Array Controller bindings:
Managed Object Context: AppDelegate.self.managedObjectContext
MainMenu.xib's Table View bindings:
Content: Array Controller.arrangedObjects
Selection Indexes: Array Controller.selectionIndexes
Sort Descriptors: Array Controller.sortDescriptors
This will work mostly the same way it does when the master and detail views are in the same window. The primary difference is that you need to bind the selection of the array controller in the detail xib to the selection of the master array controller.
It depends on how you have your app organized as to how you accomplish this. If both views are run by the same object then you can just make the master array controller an outlet connected to the controller (#property IBOutlet NSArrayController *masterArrayController;). Then in the detail xib you can bind the selection of the detail array controller to the selection of the master array controller.
If each view has its own controller you might also consider just passing the managed object from the master view to the detail view. Then you can bind to each of the attributes of the managed object in your xib file (i.e. bind to File's Owner self.detailObject.fullName). If you pass a reference I think all of the changes will go right back into the managed object context.

CoreData Binding and custom Cell

I have an app with a CoreData Database and a NSTableView.
I want to do a customCell with 3 key values from database.
So I create an NSTextFieldCell Class but the binding is only for a key value.
How I can programmatically bind a NSTableColumn with multiple key value ?
Thanks.
Here's one way to do it which foregoes the need to create a custom cell:
1) In IB, drag over an Array Controller to your Objects sidebar. Under the Attributes Inspector, set its "Mode" to Entity Mode, fill in the "Entity Name" with the name of your entity, and check "Prepares Content". Under the Bindings Inspector, set its "Managed Object Context" to managedObjectContext.
2) In IB, convert your table to be view-based. Select the "Table View" and under the Attributes Inspector, select Content Mode: View Based and change number of columns to 1.
3) In IB, select the "Table Column" and bind its Value to the Array Controller representing your object. Controller Key should be "arrangedObjects" and leave the "Model Key Path" blank.
4) In IB, select the text field (Label) in your NSTableView cell. Bind its Value to the Table Cell View. The "Controller Key" can remain blank and set the "Model Key Path" to objectValue.whateverAttributeName
There's an awesome summary and tutorial of view-based tables at Gentle Bytes.
Tim Isted created a wonderful tutorial on how to programmatically create bindings, if that's specifically what you desire at Blog # Tim Isted.

Problem with NSPopupButtonCell bindings

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

How to bind the selection of the NSTableView to the NSArrayController

I just want to be able to use the the methods of the nsarraycontroller called remove: and add:
Select the NSTableView. If the inspector window's title shows Scroll View, you need to click the table view again to select it.
In the bindings tab, connect the Selection Indexes binding to the Array Controller's selectionIndexes controller key. This is similar to binding the content to the array controller, except that you don't use the arrangedObjects key.

Resources