Sunday, November 19, 2017

#1 2017-08-15 10:28:53 am

FlameCoder
Member
From:: USA
Registered: 2009-10-28
Posts: 82

Sort Array Controller or Table

I have an array controller bound to a table view (cell based) with arrangedObjects and Model Key Path is self. It is a single column, no headers. When data is loaded into the array controller I want it to be sorted alphabetically or when displayed in the table view sort it then. Table is read only so nothing ever gets added. I thought there may be a way to accomplish this without code but haven't found it yet. Anyone know how to sort without headers showing?

Offline

 

#2 2017-08-15 05:46:47 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5175

Re: Sort Array Controller or Table

You need to set the sort descriptors of the array controller (setSortDescriptors:). But given nothing gets added, it would be easier to just sort the data yourself.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Online

 

#3 2017-08-22 01:07:46 pm

FlameCoder
Member
From:: USA
Registered: 2009-10-28
Posts: 82

Re: Sort Array Controller or Table

I can sort the data then pass it to array controller. Thanks!

Applescript:


set my arrayControllerData to sortAList_(theList)

on sortAList_(theList)
set anArray to current application's NSArray's arrayWithArray_(theList)
return anArray's sortedArrayUsingSelector_("compare:")
end sortAList_

Last edited by FlameCoder (2017-08-22 01:08:26 pm)

Offline

 

#4 2017-08-22 09:14:30 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5175

Re: Sort Array Controller or Table

FWIW, if you're running a relatively recent version of the OS you're likely to run into trouble if you keep using the underscore syntax from 10.8 -- there's a good chance Xcode will start ignoring your action handlers.

It also suggests you're not using an external editor to write your code, which tends to make life more difficult.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Online

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)