Role of the ArrayController not clear to me


Open this Scriplet in your Editor:
set sortByID to current application's NSSortDescriptor's sortDescriptorWithKey_ascending_("eCardID",true)
setSorters_(current application's NSArray's arrayWithObject_(sortByID))

setSorters_(current application’s NSArray’s arrayWithObject_(sortByID)) is equivalent to:
set my sorters to current application’s NSArray’s arrayWithObject_(sortByID). It’s just the cocoa like setter method for “sorters” that makes it so the change is visible to the interface.

Did your table work before you added these lines? There’s nothing about setting the sort descriptors that should have made your data in the table disappear. There must be something hooked up wrong somewhere. If you want to have me take a look at it, you could email me the project – I can’t really diagnose it from the little bits of code you’ve been posting

Ric

Hello Ric,

I made it work finally – it was a previous sorter which was left deep into IB.

Meanwhile I discovered a feature in NSArrayController (under special considerations):

Wow. Great. That’s why my list view was always one move late when I changed the selection by menu command and never when I clicked into the list. Two hours of sleep are gone for this. It’s not a user manual, it’s an insurance contract.
Solution to keep list and other interface elements in sync more heavy than myContrl’s selectPrevious() :

            if myContrl's canSelectPrevious() then myContrl's setSelectionIndex_(myContrl's selectionIndex()-1)


Ric,

Your offer to see my project is very generous, and I’ll send it with pleasure, but I don’t have the possibility to join it to a mail on this site.

Regards

Is there something wrong with this:

            set res to my gObjectController's removeSelectedObjects_(my gObjectController's selectedObjects())

when executed, this line makes the selection highlighting disappear, but let the item in the list.

I checked the gObjectController’s selectedObjects() – the correct item is selected
I checked the return value of “res” – it’s 1 (TRUE), so the item(s) should be deleted

The controller is set to have no multiple selection, nor empty selection.

Any ideas?

Edit : I’ve tried with and without the "my"s.

There’s nothing wrong with it – it’s doing exactly what it’s supposed to be doing. From the docs:

It doesn’t say it removes the objects from the content array, just from the selection. See removeObjects: or removeObjectsAtArrangedObjectIndexes: if you want to remove objects from the content array.

Ric

Ah ah ah, silly me.

Of course, from the description, it’s clear! I have been misled by the method’s name.

Maybe a removeObjectsFromSelection_ should have been more appropriate. Nevertheless, thank you!

(P.S. I’m always struggling with my records/dictionnaries/properties. I’ve discovered that you can refer to a key inside a dictionary inside another dictionary if you set the IB reference correctly (myArray.myReference.myKey). The point thing is to not change your structure and let these reference pointing to nothing :))