Adding a table to a document based application

I am having trouble adding a table to a document based application. I have:

¢ Created an array controller, in the document xib file, and bound it to the File’s Owner with a model key path of the property refArray.

¢ Created a single column table. The table is connected to the refTable property. The single column is bound to the array controller, arrangedObjects with a Model Key Path of Column 1.

Here is my code:

property listData : {}
property refArray : missing value
property refTable : missing value
on buttonclick_(sender)
	set recData to {{Column1:"test"}}
	tell refArray 
	end tell

I get an error: Can’t get arrangedObjects of missing value. (error -1728)

I’m sure something isn’t connected right but I’m not sure what. Probably something simple… Can anyone help?

Well, I can see right of the bat that this:


will never get you any result. arrangedObjects is an instance methods of an NSArrayController. Thus you need to send it to the array controller that manages the table.

I’d go like this:

refArray's removeObjects_(refArray's arrangedObjects())
refArray's addObjects_(recData)

A bit more objective-c-style, less applescripty. Which will really help if you decide to learn Obj-C one day. I know from experience! :slight_smile:

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

refArray is the array controller, so I think your example and mine do the same thing. Mine is just state inside of a “tell application” block instead of line by line. Correct?

Just for fun, I tried your code and got:

unrecognized function arrangedObjects. (error -10000)

As for your suggestions to write more like objective C than applescript, I must say I am going nuts with this. I am making every effort to write this stuff MORE like applescript so I can keep my sanity and actually understand what it is that I’m reading. It’s driving me crazy. Half the time I’m not really sure what the code is really doing and what it means and that is a big change for me. I can’t stand it. Any suggestion on how to help me shift my thinking is appreciated but man, it’s not easy.

So to further clarify, I have been able to connect a table in the past with an APP Delegate. However, in this case, with a document based app, I need to connect to the DOCUMENT script/class. I think that is where I’m doing something wrong.

The Array controler’s Controller Content, Controller Array is connected to “File’s Owner.refArray”. Is that correct?

If so, why would the script say “Missing value doesn’t understand …”

That makes me think it’s not connected to the right thing.


And you say that refArray is a connected binding in your nib file to an array controller object, correct? I would check that again, because this is the exact coding i’ve used over and over with great success.

Normally, the way to remove all of an array controller’s objects is this syntax:

arrayController’s removeObjects_(arrayController’s arrangedObjects())

It reads exactly as it is written, I don’t see what is difficult in this. You tell the array controller to remove objects that are all it’s objects.

Yes, the tell block is easier to read when you come from applescript, but there is no such thing in Obj-C. Thus the one-liners.

I know it’s difficult. But it gets easier once you get thru it. I was afraid of Obj-C for years, and now i’m coding 100% of the time in Obj-C, only relying on ASOC when I need to drive another app. And I have to say, i’m in love with Obj-C. And the speed, the speed! Wow…

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

So, in MyDocument.xib, I click on the Array Controller. Then I click on the Bindings Inspector. It is set to bind the Content Array to "File’s Owner with a Key Path of refArray. That’s it.

I don’t know what else to do.

Okay, I fixed it! FINALLY.

The Array Controller was connected to refArray in bindings when it should have been connected to listData. Then, the Array Controller should have been connected to the File’s Owner refArray property via outlets - not bindings.

Does that make sense?

I wish we could upload pics here to explain this stuff… it’s so hard to do in text. Anyway, thanks for the help.

Regarding the use of language, I’m a life long AppleScript programmer (since it came out and I converted from HyperTalk) and I am hard wired to use the english like syntax. The language of Objective-C is so counter-productive to me and makes me so unproductive that I could totally lose my mind daily. But I do see the potential of AS Obj-C and I love the fact that you need less interface coding. But still, when I get an example somewhere, put it in my code ” wether it works or not ” I barely understand it. :frowning:

File’s Owner? No. Not at all.

One table needs one array controller. You need to drag one array controller object from the object library in the “interface builder” part of Xcode, to the list of objects list on the left.

Then you connect a property from your app delegate object to the array controller. Then you can “talk” to your array in your script this way.

You rarely (if ever) need to connect anything to File’s Owner. This should already be connected correctly by the template already.

You need to select the array controller object, and in the bindings inspector, deploy the content array in the controller content section. In there, you need need to do this:

  1. Bind to: your app delegate.
  2. Controller Key: nothing.
  3. Model Key Path: a property dedicated to receive this data. You set it like this: property arrayContrContent : {}
  4. Value transformer: nothing
  5. in the options, make sure you check deletes on remove and handle content as compound value. These are helpfull in ASOC apps. You can optionally check Validates Immediately, if you like.

You also need to connect each table column’s in the bindings inpector to each one of your array’s entry. Like this:

  1. Check the value binding.
  2. Controller key should be arrangedObjects.
  3. Model Key Path should be the name of your array’s entry you wish to display. In the case of your example, Column1
  4. No need for a value transformer here, leave it empty.
  5. you can leave all the options checked and unchecked as they are. For now it doesnt change anything.

Then you can start adding objects in the array controller. I know it sounds like it’s complicated, but this is the way to do it. Sorry!

Do you have Shane’s book on ASOC? If you don’t you should get it. It’s worth 10 times what he’s asking for.