This is now in the code and it still does not select new rows in the table. ![]()
tell refUITableArrayController to setSelectsInsertedObjects_(true)
This is now in the code and it still does not select new rows in the table. ![]()
tell refUITableArrayController to setSelectsInsertedObjects_(true)
Also, unchecked that box, with the code above inserted and it still does not select rows.
I turned on my code that selects the row, but I am back to having THREE selections each time I add a row or select a row.
Ok, not sure what you are talking about. Could you post your entire code? It’s hard to see where the problem might like this…
Way too long to post it all.
This is in windowControllerDidLoadNib_
-- Setup notification for table selection
set theNotificationCenter to current application's NSNotificationCenter's defaultCenter()
tell theNotificationCenter to addObserver_selector_name_object_(me, "uiTableRowSelected:", "NSTableViewSelectionDidChangeNotification", missing value)
telling this subroutine to log the selected row whenever a change occurs:
on uiTableRowSelected_(sender)
tell refUITable to set numRow to selectedRow()
log "selected row " & numRow
end
Clicking the + button, runs this code:
on uiTableAddNewRow_(sender)
set recData to {{field:"value", field:"value", etc}}
tell refUITableArrayController
addObjects_(recData)
end tell
log "DONE with insertion"
....
After the + button is clicked once, this is in the log:
selected row 0
selected row -1
DONE with insertion
And… nothing is selected in the table!
So, it’s creating it selected and then unselecting it. It seems to completely ignore the checkbox for select inserted items and the same coded setting for the array. No clue what else to do besides select the new row manually (with code) and then ignore the first two selections and only take action on the third, but that seems kind of funky.
OK, I see a huge problem right there. You are using frameworks for the iOS (aka iPhone OS) development, not the Mac OS X frameworks. ![]()
Anything that begins with UI in capital is for iPhone apps development, and AppleScriptObjC is NOT supported on iPhones (sadly!).
When it begins with NS (for NextStep, Mac OS X’s ancestor) then you’re in Mac land.
You can create a separate applescript file and create an NSObject cube in your NIB with it’s name as a class, set it as the delegate for your Table View, and then use NSTableViewDelegate’s tableViewSelectionDidChange: or tableViewSelectionIsChanging:.
selected row -1 is normal. -1 means no selection. You will always get this when there is no selection after a selection change notification is sent to the table’s delegate.
FYI, row 0 means first row, because most index in Obj-C start with 0, not 1, unlike AppleScript. Probably figured it out by yourself already…
I’ll create a very simple app for you tomorrow that does all that, and share you a dropbox link so you can download and see for yourself. You can learn the same way I did with such examples. If you want me to, of course. ![]()
ASOC is very easy to use, once you’ve mastered the idea of objects and instance and class methods. Then Obj-C is much more easier to deal with after that.
FYI the subroutines that start with “ui” are my own subroutines that stand for “user interface”…
Did I happen to name them something “official”? Could that be part of the problem? I don’t know.
Anyway, I hesitate to move the table controlling code to another script file as that will open up a whole other can of worms and anti productive list of new questions for me to deal with. I think for now, unless there is a more obvious answer, I’ll just code around the extraneous selections and ignore them.
For anyone who may need this, my solution was this (hastily extracted so it may contain typos):
global gLabelTableInsertionIgnore -- to work around multiple selections when creating new table rows
on windowControllerDidLoadNib_(aController)
-- Setup notification for table selection
set theNotificationCenter to current application's NSNotificationCenter's defaultCenter()
tell theNotificationCenter to addObserver_selector_name_object_(me, "LabelRowSelected:", "NSTableViewSelectionDidChangeNotification", missing value)
end
on LabelRowSelected_(sender)
if gLabelTableInsertionIgnore = false then
-- Do stuff here
end
end
-- Anywhere I'm inserting a row, or reselecting a row, I do this:
set gLabelTableInsertionIgnore to true
tell refUITableArrayController to addObjects_(recDataToInsert)
set gLabelTableInsertionIgnore to false
it’s a clunky workaround but unless someone knows how to get the table to stop selecting multiple times on it’s own as described above, it works and I’m done.
I wonder if your problems stem from using addObject_ rather than insertObject_atArrangedObjectIndex_.
Posting the entire code or at least the relevant code with property designation is helpful to follow, otherwise, there will a lot off these replies that can be confusing.
t.
l=
I’d love to see an example of insertObject_atArrangedObjectIndex_
I’m noticing as the user selects other elements, such as making a selection in a combo box, a table selection is being registered. That seems odd to me. Again, I can filter it out as I don’t’ know how much time I can spend on this issue but ideally I’d be able to figure out what exactly is going on.
Any thoughts…?
Did you search these forums? Garanteed this has been covered before in here. Tables in general and all the associated problems have been fairly covered over the last few years…
Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)
Just searched for:
insertObject_atArrangedObjectIndex_
insertObject_atArrangedObjectIndex
and both came up with nothing.
I might abandon adding to the array controller and just add to my data property and then tell the table to upload.
This is crazy.
Tried this:
set numRow to count items of refUITableData
tell refUITableArrayController to insertObject_atArrangedObjectIndex_(recData, numRow - 1)
Got this:
unable to set argument 3 - the AppleScript value <NSAppleEventDescriptor: -1> could not be coerced to type Q. (error -10000)
You can’t search with _ in the method names. This is a compromise made by Apple because : would not work. replace the _ with : and you’ll find them. Or search for NSArrayController, since these are methods that belong to that class.
Try
tell refUITableArrayController to insertObject_atArrangedObjectIndex_(recData, (numRow - 1)as integer)
If refUITableData is your table view, tring applescript commands like count of items won’t work.
You should try:
refUITableArrayController's arrangedObject's |count|()
because count is a reserved applescript word you have to place it between || but the () after the ||.
Nope, refUITableData is my data that is in the table.
Counting items works just fine. It’s the next line that has the problem.
Coercing is what you need then. Get used to coercing a lot of data when switching from Applescript to Obj-C world.
So just like fiz said:
tell refUITableArrayController to insertObject_atArrangedObjectIndex_(recData, (numRow - 1) as integer)
Here’s a complete script:
script SMSAppDelegate
property parent : class "NSObject"
property theData : missing value
property ac : missing value
on applicationWillFinishLaunching_(aNotification)
set my theData to {"One", "Two", "Three"}
end applicationWillFinishLaunching_
on doInsert_(sender)
set theCount to ac's arrangedObjects()'s |count|()
ac's insertObject_atArrangedObjectIndex_("Four", theCount)
end doInsert_
end script
Thanks! That’s helpful. I replaced my code that was modifying the property containing data and then reloading the table with a delete and insertObject_atArrangedObjectIndex_ and now everything updates as expected. Unfortunately I don’t have time to figure out why modifying the property didn’t also update the table view. Odd… but this was very helpful and allowed me to work through my problem.