Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How can I create a Table View in Cocoa Applescript?

This is my last resort. I've searched for days and only found tutorials for iPhone and Cocoa, and I have no idea where to start. I'm looking for a way to create a Table View, and fill it with a few cells that call a handler when clicked. I've looked through the Xcode help, the Apple documentation, and countless tutorials, and I don't know what to do. I'm sure what I'm asking is possible, because usually what is possible in Cocoa is possible in Cocoa-Applescript.


Perhaps something like:


myTableView's addCell_OfType_WithHandler("This is a text cell", text, "myHandler:")


I would appretiate any responses and brief descriptions on the matter.

MacBook Pro, OS X Mavericks (10.9)

Posted on May 19, 2014 8:06 AM

Reply
4 replies

May 19, 2014 8:23 AM in response to Apple_For_The_Win

First, creating a new thread helps nothing, and confuses the issue. Try to stick with the question in one place. Do you want the question answered here or over at https://discussions.apple.com/thread/6227107?answerId=25807286022#25807286022?


Second, you need to explain where in this problem you are stuck. do you need to know how to make and display a window with a table view in ASObjC, or can you do that already and just need to know how to populate it? or are you somewhere in between? Are you working in XCode or in the Script Editor? details please.

May 19, 2014 9:17 AM in response to Apple_For_The_Win

The table view's data source (if that is what you were talking about in your other topic) is just a list of records, where each record is a row in the table and the record keys match up with a column. There are a couple of example ASObjC projects using table views: an early MacScriper tutorial (which needs to be updated and some coercions added) using a manually created data source, and an example project from Shane Stanley's AppleScriptObjC Explored ebook that uses bindings.


A table view is designed to display a group of related items, but the table view itself can be connected to an IB action. I don't know if a table view is the right approach for whatever you are wanting to do with the controls though, since you still have not explained what you are doing.

May 19, 2014 10:13 AM in response to Apple_For_The_Win

You did not answer my first question, which was not an idle question. I'll answer here, but if cross-chatter appears in a different thread I'll ignore it. You'll have to keep track of the mess yourself.


Apple_For_The_Win wrote:


At this point, I've dragged a Table View onto my window, in Xcode. I've connected it to the value "myTableView", and that's where I need help. I'm specifically trying to add cells into the table view.


I'll assume that 'connected it to the value "myTableView"' means that you've control-dragged in XCode from the table view in Main Menu.xib to a property in your applescript app delegate called myTableView. If that's not the case, please correct me.


I prefer to use an array controller for this, so please drag an array controller object into main menu.nib. once you've done that, do the following:

  1. open the applescript app delegate and add a new property called "tableController"
  2. select the table view in the object list (you may need to open some disclosure triangles to reach it). and add appropriate (an) column name(s). you can hide column titles later if you like, but having named columns makes life easier.
  3. select the array controller in the object list
    1. rename the array controller "table data"
    2. open the attributes inspector, and then add the column name(s) as key(s) in the object controller area
    3. open the bindings inspector, and where it says "controller content", open the disclosure arrow and bind the content to the App Delegate object on the model key path self.tableController
  4. select the table view in the object list again, then go down a level and select each column in turn

    for each column, open the bindings inspector, and where it says "value", open the disclosure arrow and bind the content to the Table Data object with the controller key arrangedObjects model key path being the name of the column (which is the name of the key in the controller as well)

  5. back in the applescript app delegate, add code like the following:



-- create a list of records, where each record represents a row and the column name is the record key

set myData to {{column_1_name:"hello"}}


-- convert it to an NSArray and add it to the controller content. don't forget the *my* keyword, or it won't work

set my tableController to NSArray's arrayWithArray:myData


-- may or may not be needed

myTableView's reloadData()


That should populate the table with simple text. if you want something more complicated (like buttons or links) then create the more complicated elements separately and add them to the data.

How can I create a Table View in Cocoa Applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.