Friday, November 28, 2014

#1 2010-11-12 02:06:58 am

chrisS
Member
From: Cambridge
Registered: 2010-11-06
Posts: 19
Website

selecting checkbox in table

I have a four column table in which the third column contains a checkbox.

The data comes a UNIX app and I use a repeat loop to get the data for each molecule in the file and add it to new_TableData

set record_detail to {names:num_uni_rec, tlable:new_name, isSelected:false, fileName:input_file}
copy record_detail to the end of new_TableData

and then

tell theArrayController
            removeObjects_(arrangedObjects())
            addObjects_(new_TableData)
end tell

to add the data, it then displays in the table.

To get data to set up a webview displaying a structure I used:

    set theSel to theArrayController's selectedObjects() as list
        --log theSel
        --returns {{fileName = "/Users/swain/Desktop/the_hits.smiles";isSelected = 1;names = 12;tlable = Molecule12;}}

I now need to be able to select all, select none and invert selection.

I tried this to select all.

on selectAllButton_(sender)
        tell theArrayController's arrangedObjects() to setValue_ForKey_(true, "isSelected")
end selectAllButton_

Which does nothing and I get this error in the console

08/11/2010 12:39:10    iBabel[1017]    -[_NSControllerArrayProxy setValue:ForKey:]: unrecognized selector sent to instance 0x200ba86e0
08/11/2010 12:39:10    iBabel[1017]    *** -[Viewer selectAllButton:]: -[_NSControllerArrayProxy setValue:ForKey:]: unrecognized selector sent to instance 0x200ba86e0 (error -10000)

I've also tried setValue_ForKey_(1, "isSelected")


Any help appreciated


Filed under: table, arraycontroller

Offline

 

#2 2010-11-12 03:52:48 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10683
Website

Re: selecting checkbox in table

Hi,

arrangedObjects returns a NSArray. As the objects of the array are dictionary objects
you need a repeat loop to set a single key/value


regards

Stefan

Offline

 

#3 2010-11-12 05:25:34 am

chrisS
Member
From: Cambridge
Registered: 2010-11-06
Posts: 19
Website

Re: selecting checkbox in table

Hi,

So I tried

Applescript:

set theTableItems to theArrayController's arrangedObjects()
       --log theTableItems
       repeat with n from 1 to count of theTableItems
           set theTableItemsObject to theTableItems's objectAtIndex_(n - 1)
           log theTableItemsObject

This logs

12/11/2010 11:13:08    iBabel[9769]    {
    fileName = "/Users/swain/Desktop/FLS000034.sdf";
    isSelected = 0;
    names = 1;
    tlable = Chemistry;
}

So I tried


       

Applescript:

   theTableItemsObject's setValue_ForKey_(1, "isSelected")
           
       end repeat

But I get this error

12/11/2010 11:12:00    iBabel[9734]    *** -[Viewer selectAllButton:]: -[NSCFDictionary setValue:ForKey:]: unrecognized selector sent to instance 0x2008155c0 (error -10000)

Offline

 

#4 2010-11-12 08:21:52 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10683
Website

Re: selecting checkbox in table

the problem is, NSDictionary is immutable and doesn't respond to setValue.
I recommend to use a custom class which contains the keys as properties.
Properties are automatically key-value coding compliant.

Then you can use a method like makeObjectsPerformSelector:


regards

Stefan

Offline

 

#5 2010-11-12 09:09:39 am

chrisS
Member
From: Cambridge
Registered: 2010-11-06
Posts: 19
Website

Re: selecting checkbox in table

Many thanks for this, it is very much appreciated.

I must admit this is getting more complicated than I was expecting sad

Any chance you could expand a little on how the custom class would work?

Or point me in the direction of an example? I've searched extensively and not found an example of this type of updating of an array, perhaps I now know why.

Offline

 

#6 2010-11-12 12:56:57 pm

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10683
Website

Re: selecting checkbox in table

Sorry, I don't "speak" AppleScriptObjC, because I'm still on PowerPC.

This is a very simple Cocoa example TableView_Test


regards

Stefan

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.106 seconds, 11 queries executed ]

RSS (new topics) RSS (active topics)