On Apr 30, 2013, at 1:14 PM, Chris Paveglio wrote:

> What is the best way to handle this? I have a table view (using cell views) 
> which has multiple text fields in it. I have an arrayController that holds an 
> array of the custom objects that hold the data for each tableCellView (row). 
> The array is made in the appDelegate and it always consists of text or empty 
> text strings. It all works great as described.
> 
> When I edit the text in the fields, if I remove all the text from one field, 
> it must be returning nil back to the bound object. This messes things up 
> later, because I need to return an empty string for each of the ivars in my 
> custom object, not nil.
> 
> So, my way to get around this was to essentially check if the object's ivar 
> was nil, and if so then return empty string when called upon. This works just 
> fine and I think it's efficient enough.
> 
> But is there an even better way to handle that? I tried using "null 
> placeholder" in the IB/binding options but that didn't seem to work. The 
> ivars for the custom object aren't set to "strong" and I tried that but that 
> didn't seem to help either. Is there anything I'm missing or does an 
> NSTextField always return "nil" when a value is removed from it, or can I 
> force it to return an empty string?

Yes, NSTextField has (IMHO) an imperfect understanding of the difference 
between nil and empty string. I feel your pain.

A slightly better approach might be to use key-value validation, as such:

-(BOOL)validateHeadline:(id *)ioValue error:(NSError **)outError
{
        if ( *ioValue == nil )
                *ioValue = @"";
        return YES;
}

This way you don't add side-effects to your accessors, and avoid hard to debug 
issues if you happen to use the ivar directly somewhere down the road.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

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

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

Reply via email to