Re: Selectively using formatter in table view text cell

2009-06-24 Thread Quincey Morris

On Jun 23, 2009, at 22:27, Graham Cox wrote:


I have a table view that displays the contents of a dictionary.

The values can be string data or numeric data. For numeric, I want  
to use a formatter to make it nice and pretty, but for string data I  
want to display it verbatim. If I attach a formatter to the text  
cell it refuses to validate pure string input. Is there a way to set  
up the formatter this way, or do I need to either create a special  
formatter or apply the formatter selectively for different rows (if  
so, how?).



(a) Use the delegate, something like (untested, obviously):

-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell  
forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {

if (!this is the correct column)
return;
	id objectValue = [self.delegate tableView: self  
objectValueForTableColumn:aTableColumn row:rowIndex;
	// or find the data directly from your data model, if not using a  
data source

if (objectValue isKindOfClass: [NSNumber class])
aCell.formatter = myFormatter;
else
aCell.formatter = nil;
}

(b) Add a string version of the property to your data model, using a  
suitable formatter internally, and bind the column to that.





___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Selectively using formatter in table view text cell

2009-06-24 Thread Graham Cox


On 24/06/2009, at 4:00 PM, Quincey Morris wrote:


(a) Use the delegate, something like (untested, obviously):

-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell  
forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {

if (!this is the correct column)
return;
	id objectValue = [self.delegate tableView: self  
objectValueForTableColumn:aTableColumn row:rowIndex;
	// or find the data directly from your data model, if not using a  
data source

if (objectValue isKindOfClass: [NSNumber class])
aCell.formatter = myFormatter;
else
aCell.formatter = nil;
}



Thanks! That works fine and was very easy...

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Selectively using formatter in table view text cell

2009-06-23 Thread Graham Cox

I have a table view that displays the contents of a dictionary.

The values can be string data or numeric data. For numeric, I want to  
use a formatter to make it nice and pretty, but for string data I want  
to display it verbatim. If I attach a formatter to the text cell it  
refuses to validate pure string input. Is there a way to set up the  
formatter this way, or do I need to either create a special formatter  
or apply the formatter selectively for different rows (if so, how?).


--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com