• 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
Custom NSFormatter classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom NSFormatter classes


  • Subject: Custom NSFormatter classes
  • From: Henri Häkkinen <email@hidden>
  • Date: Sun, 3 Jan 2010 02:47:00 +0200

Hello.

I have an array of custom Foo objects which I would need to display in an NSTableView object. I implement the data source delegate like this:

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
	return [arrayOfFoos count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger) row {
	return [arrayOfFoos objectAtIndex:row];
}

Then I have NSFormatter subclass FooFormatter which takes in a Foo object and converts it to a string. This formatter object is attached to the formatter property of the TextFieldCell class in the NSTableView's table column. The FooFormatter is like this:

@implementation FooFormatter

- (NSString *)stringForObjectValue:(id)anObject {
	if ([anObject isKindOfClass:[Foo class]] == NO) {
		[NSException raise:NSInvalidArgumentException format:@"Wrong object"];
	}
	Foo *foo = (Foo *)anObject;
	NSString *string;
	// ... convert foo into string ...
	return string;
}

@end

I am assuming here that the object returned by the data source objectValueForTableColumn: is passed to the formatter's stringForObjectValue: before it is displayed in the text field cell -- this seems not to be the case. I would like to keep formatting of Foo objects separate from the data source (if possible) since I intend to implement multiple different FooFormatter derived classes suited for different situations.

The Cocoa docs seem to be a little low on details on how these NSFormatter objects are supposed to work. Can anybody give me any insight? Would be appreciated. Thanks.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Custom NSFormatter classes
      • From: Patrick Mau <email@hidden>
  • Prev by Date: Why is [NSArray arrayWithObjects:] failing for me?
  • Next by Date: Re: Why do bindings make my image disabled?
  • Previous by thread: Re: Why is [NSArray arrayWithObjects:] failing for me?
  • Next by thread: Re: Custom NSFormatter classes
  • Index(es):
    • Date
    • Thread