• 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: Making iTunes-style NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making iTunes-style NSTableView


  • Subject: Re: Making iTunes-style NSTableView
  • From: Hasan Diwan <email@hidden>
  • Date: Mon, 6 Jan 2003 08:47:18 -0800

There's a NSTableView delegate method tableView:didClickTableColumn:
Implement your comparison function as a category. I've done a simple
one below:
#import <Foundation/Foundation.h>
@interface NSDictionary (DictionaryAdditions)
- (int) compare: (id) aTransaction;
@end
@implementation NSDictionary (DictionaryAdditions)
-(int) compare:(id)t {
unsigned int num1, num2;
num1 = [[self objectForKey:@"Date"] intValue];
num2 = [[t objectForKey:@"Date"] intValue];
if (num1 < num2) return NSOrderedAscending;
if (num1 > num2) return NSOrderedDescending;
else return NSOrderedSame;
}
@end
@implementation MyObject
- (void)tableView:(NSTableView *)t didClickTableColumn:(NSTableColumn
*)c {
NSMutableArray *rec=[[[NSMutableArray arrayWithContentsOfFile:@"Foo"]
sortedArrayUsingSelector:@selector(compare:)] mutableCopy];
[t reloadData];
}
@end
On Monday, January 6, 2003, at 03:18 AM, ghazban wrote:

> I want to make a NSTableView of some data from a source consisting of
> an NSMutableArray filled with NSDictionaries.
> So far I have managed (it wasn't very hard :) )
> The tricky part is that I want it to be sorted when a user clicks a
> column header in the tableview and I want it to be sorted just the way
> it acts like in for example iTunes.
> Since very much comes for free with cocoa, I wondered if this might
> too...
> If not, may I have a hint on how to accomplish what I want?
Hasan Diwan
OpenPGP KeyID: 0x7EE3855B
Fingerprint: 42F0 5758 C3EB BA1F ABD2 ED49 3390 CCF0 7EE3 855B
http://www.cs.rpi.edu/~diwanh/gpg.key

[demime 0.98b removed an attachment of type application/pgp-signature which had a name of PGP.sig]
_______________________________________________
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: 
 >Making iTunes-style NSTableView (From: ghazban <email@hidden>)

  • Prev by Date: Re: Checking OS Version with Cocoa
  • Next by Date: Re: Quickly drawing non-antialiased, discrete, pixels
  • Previous by thread: Making iTunes-style NSTableView
  • Next by thread: Re: Making iTunes-style NSTableView
  • Index(es):
    • Date
    • Thread