Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSTableView data source organisation for sorting

NSTableView data source organisation for sorting
Thread Tools
holtyboy
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 18, 2005, 06:42 AM
 
I'd welcome some views on the best way to organise a data source for an NSTableView that can be sorted by any column.

Essentially I have a 4 column table view. One column is a date / time that needs to be sortable chronologically, whilst the other columns are strings that need to be sortable alphabetically.

I'm pretty sure I've got my head around the general sorting API on NSTableView, so I don't think I have a problem getting the table view to tell the data source when the data needs to be resorted.

My problem is more to do with the organisation of the data. What is the best container to use to faciltate resorting by columns. Any pointers to examples?

Thanks,

HB.
     
poulh
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 18, 2005, 01:30 PM
 
     
holtyboy  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 18, 2005, 05:01 PM
 
Thanks for the pointer!
     
holtyboy  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 27, 2005, 05:11 AM
 
Still hitting me head against the wall on this.

I have a data source set-up and working fine for my NSTableView (an NSArray of NSDictionary). I can sort my NSArray using NSSortDescriptor for any key - no problem there.

Where I'm still a bit stuck is with detecting that the user has changed the sorting by clicking on the column headers in the NSTableView.

The examples in the old article posted seem to predate 10.3 and describe methods that I can only presume are now a bit convoluted. What is the simplest approach to take these days? Presumably there is a way to get a notification of the sort descriptor prototype for the NSTableColumn or similar?

Cheers... HB.

     
poulh
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 27, 2005, 10:43 AM
 
are you saying you can't detect the click of the column heading, or after the sort you can't get the tableView to display the newly-sorted data?
     
holtyboy  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 27, 2005, 11:23 AM
 
Thanks for the response and sorry for not being clearer with my question.

I guess what I'm really asking is: do I still have to detect for column heading clicks in the same way described in these articles, or is that now taken care of for me in some way with the sort features associated with the NSTableColumn?

i.e. the Stone article uses the didClickTableColumn delegate - is this still applicable in 10.3 ?

Code:
- (void) tableView: (NSTableView*)tv didClickTableColumn: (NSTableColumn *)tableColumn { NSImage *sortOrderImage = [tv indicatorImageInTableColumn:tableColumn]; NSString *columnKey = [tableColumn identifier]; MyDocument *doc = [self document]; PieceWork *work = [self selectedWork]; // If the user clicked the column which already has the sort indicator // then just flip the sort order. if (sortOrderImage || columnKey == [doc sortColumn]) { [doc setSortIsDescending:![doc sortIsDescending]]; } else { [doc setSortColumn:columnKey]; } [self updateTableHeaderToMatchCurrentSort]; // now do it - doc calls us back when done [doc sort]; // but reselect the one previously selected: if (work) [self selectWork:work]; }
Originally Posted by poulh
are you saying you can't detect the click of the column heading, or after the sort you can't get the tableView to display the newly-sorted data?
     
PBG4 User
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Apr 27, 2005, 01:02 PM
 
The easiest way to tell the current NSTableView delegates is to click the 2nd link under the 'Help' menu in XCode. Then type 'NSTableView' in the search field. This will give you all the applicable information on the NSTableView object, including methods & delegates.

I would say the didClickTableColumn: delegate still exists in 10.3, but check the documentation to be sure.
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
holtyboy  (op)
Fresh-Faced Recruit
Join Date: Apr 2005
Status: Offline
Reply With Quote
Apr 27, 2005, 02:29 PM
 
Thanks, but I certainly didn't imagine that the didClickTableColumn: had been deprecated for 10.3, but my question was more related to carrying out this task in a more "panther" way.

Presumably with IB allowing me to set up the "Sort Key", "Sort Selector" and "Sort Order" and the fact that my interface automatically gets up and down sort arrows (where I believe pre 10.3 this had to be created programmatically) I would have thought that didClickTableColumn: was no longer the best way of forcing a re-sort. I was hunting to find an example as to how this could be done and take advantage of the parameters you can define in IB.
     
PBG4 User
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Apr 27, 2005, 09:43 PM
 
Have you checked the NSTableView docs in XCode yet? They might answer your question. You could also search at developer.apple.com for NSTableView sample documentation and stuff.
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:18 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,