problem with date

  • hi.

    i'm still working on the same project with the view that didn't
    update. that problem is solved, but I have a new one:

    I want to display the time in the window, both as local time
    (systemTimeZone) and as GMT. I have the following code which is
    called every time the view updates:

    - (void)doTime {
    NSString *testString;
    NSString *format = @"%H:%M:%S";
    NSTimeZone *GMTZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSCalendarDate *now = [NSDate date];
    [now setCalendarFormat:format];
    testString = [now description];
    NSLog(testString);
    }

    when I try to run this, I get the following in the run log window:

    [Session started at 2007-09-15 20:43:22 +0100.]
    2007-09-15 20:43:24.417 Astro[905] *** -[NSCFDate
    setCalendarFormat:]: selector not recognized [self = 0x342f00]
    2007-09-15 20:43:24.419 Astro[905] An uncaught exception was raised
    2007-09-15 20:43:24.419 Astro[905] *** -[NSCFDate
    setCalendarFormat:]: selector not recognized [self = 0x342f00]
    2007-09-15 20:43:24.419 Astro[905] *** Uncaught exception:
    <NSInvalidArgumentException> *** -[NSCFDate setCalendarFormat:]:
    selector not recognized [self = 0x342f00]

    when I turn the [now setCalendarFormat:format]; line into a comment,
    the code runs, but then the string is in the default format which is
    not what I want. BTW, I have code sense on, so I know I didn't put
    any typos in that line.

    I can't figure out what's going on here. can anyone help me out? is
    the format string FUBAR?

    --
    GPG Key ID: 92AD877F7E4E32B9
    Fingerprint: 16B0 7DCD 3AB0 0C45 F5FD  581D 92AD 877F 7E4E 32B9
  • On 9/15/07, H M <hmiersch...> wrote:

    > I can't figure out what's going on here. can anyone help me out? is
    > the format string FUBAR?

    Read the exception message, it tells you exactly what you need to know. :)

    The following line is your problem ...

    NSCalendarDate *now = [NSDate date];

    ... you are creating an instance of NSDate and then proceed to treat
    it as an NSCalendarDate.

    -Shawn
  • On 15. Sep 2007, at 20:53, Shawn Erickson wrote:

    > On 9/15/07, H M <hmiersch...> wrote:
    >
    >> I can't figure out what's going on here. can anyone help me out? is
    >> the format string FUBAR?
    >
    > Read the exception message, it tells you exactly what you need to
    > know. :)
    >
    > The following line is your problem ...
    >
    > NSCalendarDate *now = [NSDate date];

    thanks for pointing that out. I've changed it, and now it works. I've
    also added a timer that calls that method every second to put the
    current time into those fields.

    but i've noticed something strange: when I move the sliders, the
    numbers in those text fields get blurred, kinda like when you write a
    number down and then write another number in the same place without
    erasing the old number first. this only happens when I move a slider,
    but not when I change the size of the window or when the timer calls
    that method...

    --
    GPG Key ID: 92AD877F7E4E32B9
    Fingerprint: 16B0 7DCD 3AB0 0C45 F5FD  581D 92AD 877F 7E4E 32B9
  • On Sep 15, 2007, at 4:50 PM, H M wrote:

    > but i've noticed something strange: when I move the sliders, the
    > numbers in those text fields get blurred, kinda like when you write
    > a number down and then write another number in the same place
    > without erasing the old number first. this only happens when I move
    > a slider, but not when I change the size of the window or when the
    > timer calls that method...

    I believe it is due to the resource-saving moving of the pixels in
    your view that is by default used by the OS to minimize the amount of
    re-drawing that must be done.

    You can force the OS to redraw your view each time it scrolls which
    should solve your issue by using the setCopiesOnScroll: method of the
    NSClipView that contains your NSScrollView. I'm a newbie myself and I
    just discovered this last week, so if I'm wrong, someone please slap me.
  • On 15. Sep 2007, at 23:45, Paul Bruneau wrote:

    > On Sep 15, 2007, at 4:50 PM, H M wrote:
    >
    >> but i've noticed something strange: when I move the sliders, the
    >> numbers in those text fields get blurred, kinda like when you
    >> write a number down and then write another number in the same
    >> place without erasing the old number first. this only happens when
    >> I move a slider, but not when I change the size of the window or
    >> when the timer calls that method...
    >
    > I believe it is due to the resource-saving moving of the pixels in
    > your view that is by default used by the OS to minimize the amount
    > of re-drawing that must be done.
    >
    > You can force the OS to redraw your view each time it scrolls which
    > should solve your issue by using the setCopiesOnScroll: method of
    > the NSClipView that contains your NSScrollView. I'm a newbie myself
    > and I just discovered this last week, so if I'm wrong, someone
    > please slap me.

    the time is not (supposed to) be shown in my custom view. I have 2
    text fields above that view for the time (one for the system's time
    zone, the other for GMT) and they are the ones that get blurred. but
    it just occurred to me that i could remove the call to the doTime
    method from the drawRect method in which case the doTime method would
    only be called by the timer which would be sufficient.
    hmm... when I move a slider, the doTime method gets called several
    times a second. is it possible that something stumbles over its own
    feet trying to keep up with all the calls, thereby causing the blurring?

    --
    GPG Key ID: 92AD877F7E4E32B9
    Fingerprint: 16B0 7DCD 3AB0 0C45 F5FD  581D 92AD 877F 7E4E 32B9
  • > ... i could remove the call to the doTime method from the drawRect
    > method ...

    I did that, and now the text fields don't get updated for as long as
    I drag the slider. not ideal, but better than having it all blurry.

    --
    GPG Key ID: 92AD877F7E4E32B9
    Fingerprint: 16B0 7DCD 3AB0 0C45 F5FD  581D 92AD 877F 7E4E 32B9
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today