I have created a custom formatter for my (read-only) table column. It looks like this:
- (NSString *)stringForObjectValue:(id)anObject
{
NSAssert([anObject isKindOfClass:[NSString class]] && anObject != nil,
@"invalid object");
if ([anObject isEqualToString:@""])
return @"EMPTY";
else
return [anObject stringByAppendingString:@"++"];
}
Very simple. The corresponding objects are just strings, so it’s an string-to-string formatter. All non-empty string objects are returned with @"++" appended to them. Empty string objects should be turned into the @"EMPTY" string.
The @"++" gets appended to non-empty strings just fine.
The problem is, @"EMPTY" never gets shown! My formatter is never called by Cocoa when the underlying object is the empty string. The corresponding row just keeps being empty, instead of showing my requested @"EMPTY".
Any ideas?
I’ve tried your code. And it works for me. Here’s the code (slightly modified):
For non-empty string:
result:
Now try for empty string:
Result:
So your code is really working. Perhaps you can show us other portion of your code (the one who calls your function perhaps), so we can really spot the trouble. Your code, as posted, is really working.