DateFormatter on table view text cell not functioning correctly?

13 views
Skip to first unread message

Luke

unread,
May 23, 2019, 5:02:11 PM5/23/19
to Cappuccino & Objective-J

As far as I can tell, the date formatters on tableview cells aren't working... but perhaps I'm missing something.


I have a column in the table bound to a CPDate property on arrangedObjects.  The TextCell in that column has a DateFormatter attached and that was set for the 'short' format for both date and time. 


What happens is the original rendering of text is the cell is some full format and always shows a date of midnight new year's day for the year 2000 (though adjusted to Pacific Time this is actually rendered as late in 1999).  The actual object has a different value for its CPDate, which I've checked in the debugger and tracing to log.   


When I click on the cell to edit it, I get the correctly formatted text for this (wrong) date displayed in the cell editor, but if I change the date shown "1999-12-31", then I can never get the edited text to validate and the edit accepted. 

If I just accept this 1999-12-31 date, then the underlying object has it's property set for this date (so the binding is working) and this will result in my model being updated with this dodgy date.


Is there some odd interaction with cells, formatters and binding?

I'm pretty sure I have the xib set up right.


 


Keary Suska

unread,
May 23, 2019, 6:19:58 PM5/23/19
to objec...@googlegroups.com
Do you set the formatter in Interface Builder, or programmatically? If you instead set the formatter in a tableview delegate method, does it work better? Note that CPDateFormatter doers not handle null dates properly, o you might need to handle that case differently.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
> --
> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
> To post to this group, send email to objec...@googlegroups.com.
> Visit this group at https://groups.google.com/group/objectivej.
> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/1ef0e4fa-1f74-40bc-901a-5b1a984c5c81%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Luke Evans

unread,
May 23, 2019, 8:21:42 PM5/23/19
to objec...@googlegroups.com
Thanks.

I set it in Interface Builder, which is certainly what I’d prefer to do, but I’ll embark on some exploration of other ways.
Too bad about not handling nulls as well, as this is an optional date and I had set the Null placeholder in the binding in the hope of saying “No date set”, but indeed that isn’t working either. 

Keary Suska

unread,
May 24, 2019, 9:49:07 AM5/24/19
to objec...@googlegroups.com
Setting in IB should work, at least it has worked for me in cell based table views (as long as you are using a somewhat recent version of Capp). If you get the same date display whether the date is null or not, it could mean that the formatter is being applied before the cell value is set, or something odd with the null placeholder. Reloading the table might fix the cells that have a valid date in them in the first case, and putting a specific date as the null placeholder might reveal the issue.

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

> --
> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
> To post to this group, send email to objec...@googlegroups.com.
> Visit this group at https://groups.google.com/group/objectivej.
> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/29042D53-A07B-407D-8A4A-3CDEAD1B21E1%40gmail.com.

Keary Suska

unread,
May 24, 2019, 10:10:53 AM5/24/19
to objec...@googlegroups.com
Actually, trying to set the formatter in a delegate method might not actually work, but you at least can check to see whether the formatter is being set at all. I think when I ran across this issue some time ago I ended up using data source methods and pre-formatting the cell value. Somewhere along the line that issue was fixed, as now I use bindings and formatters set in IB.

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

> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/92516D26-C430-4E76-B793-C940B18D8B12%40esoteritech.com.

Luke

unread,
May 24, 2019, 4:00:30 PM5/24/19
to Cappuccino & Objective-J
This is pretty infuriating. 

With binding and the formatter set on the cell in IB, the text is always formatted incorrectly as some kind of full format and always displays the same value:
"Fri Dec 31 1999 16:00:00 GMT-0800 (Pacific Standard Time)"

However, when I click to edit the cell, I see the correct format, but the wrong value (the value displayed is always this "1999-12-31" for my date-only format).
But... when I enter a new date in the correct format, this date is set on my object and correctly saved to my server, even though the cell display returns to "Fri Dec 31 1999 16:00:00 GMT-0800 (Pacific Standard Time)" again.

In other words, somehow reading the current value and formatting it is broken (and interestingly in a way that has two formats - display and edit).
Editing/writing the value seems to work. 

Cappuccino doesn't seem to have an NSCell equivalent, which makes it a bit more difficult to hook into what is going on.  

I think I'll write a custom formatter and watch what happens inside it.

Are you using the stock Cappuccino 1.0 frameworks?  Wondering how you have this working with binding (same as me) and set up in IB (same as me).  I've actually wondered if Xcode somehow changed what it persists in the xib for formatters on cells, but I suppose there would be a flurry of error messages if the xib->cib conversion failed and I'm seeing nothing. 



On Friday, May 24, 2019 at 7:10:53 AM UTC-7, Keary Suska wrote:
Actually, trying to set the formatter in a delegate method might not actually work, but you at least can check to see whether the formatter is being set at all. I think when I ran across this issue some time ago I ended up using data source methods and pre-formatting the cell value. Somewhere along the line that issue was fixed, as now I use bindings and formatters set in IB.

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

> On May 24, 2019, at 7:49 AM, Keary Suska <cappu...@esoteritech.com> wrote:
>
> Setting in IB should work, at least it has worked for me in cell based table views (as long as you are using a somewhat recent version of Capp). If you get the same date display whether the date is null or not, it could mean that the formatter is being applied before the cell value is set, or something odd with the null placeholder. Reloading the table might fix the cells that have a valid date in them in the first case, and putting a specific date as the null placeholder might reveal the issue.
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
>> On May 23, 2019, at 6:21 PM, Luke Evans <luke...@gmail.com> wrote:
>>
>> Thanks.
>>
>> I set it in Interface Builder, which is certainly what I’d prefer to do, but I’ll embark on some exploration of other ways.
>> Too bad about not handling nulls as well, as this is an optional date and I had set the Null placeholder in the binding in the hope of saying “No date set”, but indeed that isn’t working either.
>>
>>
>>> On May 23, 2019, at 3:19 PM, Keary Suska <cappu...@esoteritech.com> wrote:
>>>
>>> Do you set the formatter in Interface Builder, or programmatically? If you instead set the formatter in a tableview delegate method, does it work better? Note that CPDateFormatter doers not handle null dates properly, o you might need to handle that case differently.
>>>
>>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to objec...@googlegroups.com.
>> To post to this group, send email to objec...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/objectivej.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/29042D53-A07B-407D-8A4A-3CDEAD1B21E1%40gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to objec...@googlegroups.com.

Luke

unread,
May 24, 2019, 5:13:24 PM5/24/19
to Cappuccino & Objective-J
> I think I'll write a custom formatter and watch what happens inside it.
...  but I can't get my custom formatter class to load properly from the cib:
"Cappuccino [error]: Unable to find class TestFormatter referenced in cib file."

Xcode let me pick the custom class, so obviously the XcodeCapp magic was all working, and my custom class is sitting there in my project. 
I guess some other piece of string has snapped :(

Keary Suska

unread,
May 25, 2019, 10:18:05 AM5/25/19
to objec...@googlegroups.com
I am using bindings and date formatters, all specified in IB, for cell-based tables only. I am thinking that the strange date is what happens when the formatter get a null value. Did you try clearing the null placeholder to see if that changed anything? If you send me your project, or just a repro, I would be happy to look at it.

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

> To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
> To post to this group, send email to objec...@googlegroups.com.
> Visit this group at https://groups.google.com/group/objectivej.
> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/276c9f84-634a-4822-b16f-2d749f91e548%40googlegroups.com.

Luke Evans

unread,
May 25, 2019, 3:44:03 PM5/25/19
to objec...@googlegroups.com
It’s comforting at least that you have all this working.

Thanks for the kind offer to review the code too.
I can see the object has non-null value for the CPDate value (I log the values that are created in the array bound to the CPArrayController for the table). At least their -description output looks like a good text timestamp with the expected date/time at the server.

I’ll play a little more and hardcode some date values, I’d certainly appreciate your help if I can’t make progress.

Sent from my iPad
> You received this message because you are subscribed to a topic in the Google Groups "Cappuccino & Objective-J" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/objectivej/Vpa6pdOgYao/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to objectivej+...@googlegroups.com.
> To post to this group, send email to objec...@googlegroups.com.
> Visit this group at https://groups.google.com/group/objectivej.
> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/C75A806F-0B5B-4755-B406-81F6CB50BB12%40esoteritech.com.
Reply all
Reply to author
Forward
0 new messages