Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 673433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:35:43+00:00 2026-05-14T00:35:43+00:00

I have a problem with sorting NSTableColumn contents. In my NSTableView there are three

  • 0

I have a problem with sorting NSTableColumn contents. In my NSTableView there are three columns: File, Size, Path. The contents are stored in NSMutableArray. Each object in this array is a NSDictionary containing three keys: file, size and path – value for each is a NSString.

In Interface Builder, in each Table Column’s attributes I can choose sorting options:
Selector: IB entered “compare:” which I think is ok, because I compare NSStrings.
Sort Key – and that’s the problem I think – I don’t know what to enter here.

Any clues? If you’ve got questions about my code, please ask.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:35:43+00:00Added an answer on May 14, 2026 at 12:35 am

    So I found the complete solution.

    First, go to Interface Builder. Select column that you want to sort. Go to the column’s inspector and choose the first button to see the “Table Column Attributes”. Set appropriate values (literally, no ” or ‘ or @ are needed):

    Sort key: file
    

    where ‘file’ is the key of dictionary that contents is shown in your column.

    Selector: compare:
    

    standard sort function.

    Now, save all the changes here and jump to Xcode, to the class in which is the model, source of the data shown in NSTableView. You should already know that you need two methods there:

    -(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
    -(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn
     *)tableColumn row:(NSInteger)row
    

    these two are needed to conform the NSTableDataSource informal protocol. You can read about it at the MacDev Center.

    Now all you have to do is to add a new method:

    -(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange: (NSArray *)oldDescriptors
    

    it can contain a very simple code that will do the thing:

    -(void)tableView:(NSTableView *)tableView sortDescriptorsDidChange: (NSArray *)oldDescriptors 
    {       
        NSArray *newDescriptors = [tableView sortDescriptors];
        [results sortUsingDescriptors:newDescriptors]; 
        //"results" is my NSMutableArray which is set to be the data source for the NSTableView object.
        [tableView reloadData]; 
    }
    

    And that’s all. It’s working in my app, hope it will work in your case 😀 Everything should work automatically. I’ve just saved all files and Built the app. And it worked. 🙂

    Site that helped me:
    CocoaDev: SortingNSTableView

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently faced with a difficult sorting problem. I have a collection of
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via
I do not have problem as such but I am quite new to Ruby.
I have a problem using the Java search function in Eclipse on a particular
I have a problem with a little .Net web application which uses the Amazon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.