Basic Core Data Bindings - unclear


#1

I setup my xcdatamodeld, made my array Controller with the name Cars. Setup my Table Views so that they look like the diagram on page 178.

Next I try to do the bindings, but here everything seems wrong. What I see in the book is not what I see in Xcode . First on page 185 I get a table of bindings, 2 Col 0s a col 1 and col 2. Since these are in no order I look at the key path name and figure that value of Col 2 Check Box will deal with the row of check boxes in my table, I go to “Document outline” click on “Table Column - Special” with that selected I could go to the Bindings Inspector and in “Value” I check on bind to “Car” and fill in the objectValue.onSpecial. Or am I suppose to click the down arrow and go “Table Cell View => Check Box” ? and then put the bind to “Car” and fill in the objectValue.onSpecial? Im a little confused on which is correct, it’s not very clear.

That aside, unable to bind my tables I figure that I will bind the “Add” and “Remove” button and go back to the table later. I control click my Array Controller , drag over to “Add” , let go and the connection disappears. I try to control click from “Add” and drag to the Array Controller (Cars) same thing happens.

I am unable to figure out how the bindings work, the diagrams don’t seem to help me and I’m getting so frustrated, please help

PS I am using Xcode 4.4.1 with Mountain Lion. And both the Third and Fourth edition of the book


#2

I would recommend that you read Apple’s CoreData material, starting with Introduction to Core Data Programming Guide.

This will enable you to feel more self confident and thus to smooth out the differences you will encounter. The BNR books are good guides, but they are not substitutes for Apple’s documentation.


#3

My problem is not in understanding Core Data ( I have read the document that you mentioned a few times), my problem was 1. being a second language I was not understanding the instruction of author and 2. My understanding of how Bindings work is very much lacking. When I click on “Table Column” , for example, and then Binding Inspector, I get Value, Value with Pattern, Availablity, Font, Text Color, and Parameters. I just can’t figure out how to know which one to use.

I did delete my carLot project and went and did each step again, reading ever so carefully and managed to figure out the bindings (I think anyway), my project does not crash when I run it. I also was able to connect my Add and Remove buttons to my array controller.

My one big problem is that I can not edit anything. I have the CarLot app running but everything is blank, if I click/ double click under Make/model I can not write, if I hit add nothing happens (I have nothing to add) On page 186 I found this line “Before continuing, use the Attributes Inspector to set the Behavior of each Static Text Field to Editable” . Done, but still can not add a car.

Any ideas?


#4

Then, Apple’s documentation can help:

  • Introduction to Cocoa Bindings Programming Topics
  • Core Data and Cocoa Bindings

#5

For anyone else having this problem, I have no idea what caused it, but was able to fix it and now my app works as intended.

I downloaded the code from the Big Nerd Ranch site to compare what the author had and what I had and EVERYTHING was identical, all my bindings, views, everything EXCEPT for one little thing: I had some “shared array controller” under my Cars array controller. I don’t remember the actual name , it began with shared and it had the icon of the array controller. I deleted that extra array controller and WALLA! my app worked.

I redid this app 3 times and I’m sure I did not add a second array controller. The first two times I did the app I had other problems, like not following or understanding what I was reading, and I deleted those so I can not be sure if the mysterious 2nd array controller was there too. But I am 100% sure I did not add the 2nd array controller on my 3rd try.

Any idea of how that happened? Besides actually adding it is there some weird step I did that may have caused the app to think I needed a shared array controller? Just trying to learn from my mistakes, any help in figuring out the mystery would be welcomed.


#6

I did a little test app following the instructions for the carLot app. At the moment I create the Array Controller there is only itself, after going to bindings to do the bindings stated at the bottom of page 179 ( Parameters > Managed Objects Context > Bind to > File’s Owner ) a “Shared User Defaults Controller” pops up under my car array controller. Completing the instructions and I come across the same problems I had further up in this thread. Deleting the Shared User Defaults Controller fixes the problem.

Where did this array controller come from? Am I the only person that is having this issue, or is this just part of Xcode? Just trying to clear up the problem in my head. I would really like someone that understands this to please enlighten me :slight_smile:

Thanks for your time.


#7

SheraFoo,

A few notes: “Shared User Defaults Controller” represents NSUserDefaults; it’s not an array controller. It is usually created automatically by Xcode if you inadvertently choose it in the bindings pop-up, instead of the Array Controller. Try this with a fresh XIB file: drag in an Array Controller and try binding something to it. Note that if you select Shared User Defaults Controller, it will now show that in the Objects list. We don’t use the Shared User Defaults Controller in the book.

Bindings can be very tricky to get right, and sometimes Xcode is less than helpful with things like the above (automatically creating the Shared User Defaults Controller). As a beginner when you’re still trying to figure it all out sometimes the best course of action is just to wipe out the contents of the XIB file and try again. Before you do that, though, one trick to double-check the bindings you’ve made is to Ctrl-Click on the various top level objects to show their connection panel (this also shows bindings).

Hope this helps. Also, in one of your earlier messages you indicated that you were trying to bind the column; in this chapter we are using View-based table views, which bind the individual controls to the table cell views, and the table view itself to the array controller. With cell-based table views we bind the table columns.

Adam