I’m trying to get multiple selected rows of my table. Using an Array, but even if I select more than one row, all I get back is the last selected… this is the code I use:
set vSelectedRows to plugstable's selectedRow() as integer
already tried with selectedRows but can’t get it to work…
Anyone a solution?!?
Thanks!
hmmm. This returns
[number of indexes: 6 (in 1 ranges), indexes: (1-6)]
Can’t get a repeat like this to work:
set vSelectedRows to plugstable's selectedRowIndexes()
set vArrangedDS to arrangedObjects of theDParray
repeat with vRow in vSelectedRows
set vRow2Move to vArrangedDS's objectAtIndex_(vRow)
set vPlugName to (vRow2Move's valueForKey_("plugname"))
log vPlugName
end repeat
set vSelectedRows to plugstable's selectedRowIndexes()
set vArrangedDS to arrangedObjects of theDParray
log vSelectedRows
repeat with vRow in (vSelectedRows as list)
log vRow
--set vRow2Move to vArrangedDS's objectAtIndex_(vRow)
--set vPlugStatus to (vRow's valueForKey_("plugswitch")) as boolean
--set vPlugName to (vRow2Move's valueForKey_("plugname"))
--log vPlugName
end repeat
vRow logs exactly the same as vSelectedRows… bummer
Unlike AppleScript (Matt Neuburg calls it the “English-likeness” Monster), Objective-C is a real (programming) language. Personally it took 2 weeks to understand the basics of AppleScript and half a year to understand the basics of ObjC.
set vSelectedRows to plugstable's selectedRowIndexes()
set vArrangedDS to arrangedObjects of theDParray
log vSelectedRows
set vRows2Switch to (vSelectedRows's allObjects()) as list
repeat with vRow in vRows2Switch
set vRow2Move to vArrangedDS's objectAtIndex_(vRow)
--set vPlugStatus to (vRow's valueForKey_("plugswitch")) as boolean
set vPlugName to (vRow2Move's valueForKey_("plugname"))
log vPlugName
end repeat
Where plugstable is just the table en the theDParray the array…
But I’ll try to ask the array controller for selectedObjects()…
There are two ways to the user can use the application I’m working on: by clicking on a checkbox column or to select mulitple rows and use a menu item.
The code now i:
set vSelectedRows to theDParray's selectedObjects()
if (count vSelectedRows) is 1 then
set vClickedRow to plugstable's clickedRow() as integer
set vArrangedDS to arrangedObjects of theDParray
set vRow2Move to vArrangedDS's objectAtIndex_(vClickedRow)
--set vPlugStatus to (vRow's valueForKey_("plugswitch")) as boolean
set vPlugName to (vRow2Move's valueForKey_("plugname"))
log vPlugName
else if (count vSelectedRows) > 1 then
log vSelectedRows
else if (count vSelectedRows) is 0 then
log "no row selected!"
end if
This works well, but there will probable be a better way to script this nicely…
This gets the selections from the table.(tIndexSet)
Then it gets a new array containing the objects, in this case from the array pRecordData.
Then it repeats through the array of recs (each tRec is an NSMutableDictionary)
It then changes a key value to the title of a popup menu.
Then it writes the record back into the array and finally reloads the data into the table.
on chooseCategory_(sender)
set tIndexSet to pTransactionTable's selectedRowIndexes()
set tArray to pRecordData's objectsAtIndexes_(tIndexSet)
repeat with tRec in tArray
set tIndex to pRecordData's indexOfObject_(tRec)
set tValue to pCategoryMenu's title()
set tKey to "category"
tRec's setValue_forKey_(tValue,tKey)
pRecordData's replaceObjectAtIndex_withObject_(tIndex,tRec)
end repeat
pTransactionTable's reloadData()
end chooseCategory_