• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do you set the NSTableView Indicator Image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you set the NSTableView Indicator Image


  • Subject: Re: How do you set the NSTableView Indicator Image
  • From: Ondra Cada <email@hidden>
  • Date: Mon, 18 Mar 2002 14:35:48 +0100

On Monday, March 18, 2002, at 08:27 , Noah Lieberman wrote:

Additionally, neither in ObjC or Java can I get the table column to stay
highlighted... Is shows blue when you click it then goes back to being
grey...

Surely someone else has created an NSTableView with sorting? Help?

Yup, many times. No problem at all:

typedef struct { NSString *key; BOOL ascending; } _sortCtxt;
int _sortByColumnIdentifier(id left, id right, void *ctxt) {
NSString *key=((_sortCtxt*)ctxt)->key;
id lefto,righto;
int order=0;

if (key) {
if (((_sortCtxt*)ctxt)->ascending) {
lefto=[left objectForKey:key];
righto=[right objectForKey:key];
} else {
lefto=[right objectForKey:key];
righto=[left objectForKey:key];
}
if ([lefto isKindOfClass:[NSString class]])
order=[(NSString*)lefto caseInsensitiveCompare:righto];
else order=[(NSNumber*)lefto compare:righto]; // works for dates too, cast just to get rid of warning
}
return order;
}
-(void)sortTableColumn:(NSTableColumn*)col ascending:(BOOL)asc select:(NSMutableSet*)origSelection {
_sortCtxt ctxt={[col identifier],asc};
NSMutableSet *selection=origSelection?origSelection:[self saveCurrentSelection]; // you guess what it does

if (sortedColumn) [table setIndicatorImage:nil inTableColumn:sortedColumn]; // sortedColumn a property
if ((sortedColumn=col))
[table setIndicatorImage:asc?sortedAsc:sortedDesc inTableColumn:sortedColumn]; // sortedAsc/Desc images
[shown sortUsingFunction:_sortByColumnIdentifier context:&ctxt]; // shown the mutableArray shown in table
[table setHighlightedTableColumn:col];
[table reloadData];
[self restoreSelectionFrom:selection];
}

Of course, never tried it in Java (and, hopefully, never will have to ;)
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >How do you set the NSTableView Indicator Image (From: Noah Lieberman <email@hidden>)

  • Prev by Date: Re: Some good docs viewer?
  • Next by Date: Re: Newbie with stupid question
  • Previous by thread: How do you set the NSTableView Indicator Image
  • Next by thread: OT: Re: Slow Project Builder...
  • Index(es):
    • Date
    • Thread