Removing sort descriptors on a sorted NSTableView / NSOutlineView

Cocoa, General

I’ve discovered that some people may want to programatically remove the sort descriptors for their tableview:

Removesortdesc1

This is easy to do with a little code:

- (IBAction)removeSorting:(id)sender {
    [tableView setSortDescriptors:[NSArray array]];    
}

However, you may want your users to be able to do it. It is fairly simple to add a button in the corner view of your table that does this:

Removesortdesc2

In your awakeFromNib method you can easily add a bit of code that adds this button and invokes the above “removeSorting:” method:

    NSRect buttonFrame = [[tableView cornerView] frame];
    NSButton *button = [[NSButton alloc] initWithFrame:buttonFrame];
    [button setBezelStyle:NSSmallSquareBezelStyle];
    [button setTitle:@“X”];
    [button setTarget:self];
    [button setAction:@selector(removeSorting:)];

    [tableView setCornerView:button];
    [button release];

Have Fun, and note that I recommend that you don’t have auto-scrollbar hiding turned on when you use this (otherwise, the corner view won’t be visible!)

-corbin

Previous Post
no_thumbnail
professional santa barbara mountain unicycle pictures
Next Post
no_thumbnail
Photography

3
Leave a Reply

avatar
500
3 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
3 Comment authors
wpSlidercorbinRay Recent comment authors
  Subscribe  
Notify of
Ray
Guest
Ray

There is something that bothers me about having the [X] all the way to the side like that. It is clever, and I know that clicking on that [X] while one of the columns is selected deletes the sort ordering on that column, but bothers me that if you want to delete the sort ordering on that far-left-hand column, you select it and then go all the way to the right. It seems to me there is another way. Say the column is sorting ascending. The icon shown is the right-side-up triangle. Click on the column header. It changes to… Read more »

wpSlider
Guest
wpSlider

Geez Corbin,

I was just passing by and noticed this post. I don’t know, but if I was you, I would really, really long for my Delphi programming days; That code is just shocking!
No matter how many times I’ve tried to make myself interested in Mac Apps development, it’s the absense of a proper (Delphi VCL like) framework that really spoils it for me.

(c) 2008-2019 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

109 queries. 0.482 seconds.

Log in