Instance Method

stringForObjectValue:

The default implementation of this method raises an exception.

Declaration

- (NSString *)stringForObjectValue:(id)obj;

Parameters

anObject

The object for which a textual representation is returned.

Return Value

An NSString object that textually represents object for display. Returns nil if object is not of the correct class.

Discussion

When implementing a subclass, return the NSString object that textually represents the cell’s object for display and—if editingStringForObjectValue: is unimplemented—for editing. First test the passed-in object to see if it’s of the correct class. If it isn’t, return nil; but if it is of the right class, return a properly formatted and, if necessary, localized string. (See the specification of the NSString class for formatting and localizing details.)

The following implementation (which is paired with the getObjectValue:forString:errorDescription: example above) prefixes a two-digit float representation with a dollar sign:

- (NSString *)stringForObjectValue:(id)anObject {
 
    if (![anObject isKindOfClass:[NSNumber class]]) {
        return nil;
    }
    return [NSString stringWithFormat:@"$%.2f", [anObject  floatValue]];
}

See Also

Getting Textual Representations of Object Values

- attributedStringForObjectValue:withDefaultAttributes:

The default implementation returns nil to indicate that the formatter object does not provide an attributed string.

- editingStringForObjectValue:

The default implementation of this method invokes stringForObjectValue:.