How to update an AppDelegate property via editing a Table View Cell?

Hello all,

I’m trying to update an AppDelegate property by editing a Table View Cell.

I created a sample project (Table View example project with array controller) using tips from the answer to this post:How to use a sidebar with AppleScript? - Stack Overflow

I’m using macOS Big Sur (11.6.8) and Xcode 12.5.1.

My source archive can be downloaded here: https://drive.google.com/file/d/1uHmrw1QB-lXsK5sCLWpTOP9u8fe-Ludz/view?usp=share_link.

Here’s my AppDelegate script:

--
--  AppDelegate.applescript
--  Table View Example
--  
--

script AppDelegate
	property parent : class "NSObject"
    property msg : ""

	-- IBOutlets
	property theWindow : missing value
    property tableViewData : missing value
    property arrayController : missing value
    property showTableViewData : missing value
    
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened
        appInit()
	end applicationWillFinishLaunching_
	
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
	
    on appInit()
        
        set my msg to (current date & return & return & "Initializing…") as string
        delay .5
        initTableView()
        set my msg to (current date & return & return & "Ready.") as string
        delay .5
        
    end appInit
    
    on initTableView()
    
        set my tableViewData to {}
        set my tableViewData to {{adName:("C21 ad" as string), pageNumber:("001" as string)}, {adName:("ERA ad" as string), pageNumber:("002" as string)}}

    end initTableView
    
    on showTableViewData_(sender)

        set my msg to (current date & return & return & "showing tableViewData....") as string
        delay .5

        set displayText to ""
        repeat with thisRecord in tableViewData
            
            display alert "adName: " & (adName of thisRecord as  string) & return & "pageNumber: " & (pageNumber of thisRecord as  string)

        end repeat
        
        set my msg to (current date & return & return & "Ready.") as string
        delay .5

    end showTableViewData_

end script

How it works

As you can see I have hardcoded two records which I use to populate the tableViewData property on initialization which in turn is displayed in the table view. For some reason the adName data is not being displayed, but that bug is not what this post is about.

App initialized:
1. app initialized

Clicking the button reads the tableViewData property, iterates the records displaying them via an alert (so we can see it’s contents).

Record displayed:
2. record display.PNG

Aside from the adName not displaying, so far so good.

Next, I edit the pageNumber table view cell for the first record (changing it from “001” to “777” and hitting return). When I click the button the first record is again displayed which still shows a pageNumber value of “001” (instead of the “777” value I entered). I’m not sure how to get the changes I make via editing the table view cell to be saved to my tableViewData property.

Record display after edit:
3. record display after edit

Selecting the bindings setting “Continuously Updates Value” doesn’t seem to help.

Here are some shots of the App Delegate, Array Controller, and Table View Cell attributes, connections, and bindings:






Thanks for taking the time to look this over.

Using a script object worked for this (answer provided on another forum):

on appInit()
    
    set my msg to (current date & return & return & "Initializing…") as string
    delay .5
    initTableView()
    set my msg to (current date & return & return & "Ready.") as string
    delay .5
    
end appInit

on initTableView()

    set my tableViewData to {}
    set my tableViewData to {makeAd("C21 ad", "001"), makeAd("ERA ad", "002")}

end initTableView

on showTableViewData_(sender)

    set my msg to (current date & return & return & "showing tableViewData....") as string
    delay .5

    set displayText to ""
    
    repeat with thisRecord in tableViewData
        
        display alert "adName: " & (adName of thisRecord as  string) & return & "pageNumber: " & (pageNumber of thisRecord as  string)

    end repeat
    
    set my msg to (current date & return & return & "Ready.") as string
    delay .5

end showTableViewData_

on makeAd(nameOfAd, pageNr)
    script ad
        property adName: nameOfAd
        property pageNumber: pageNr
    end script
    return ad
end makeAd1