• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: GUI Time Field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GUI Time Field


  • Subject: Re: GUI Time Field
  • From: "Shawn Erickson" <email@hidden>
  • Date: Tue, 22 Apr 2008 13:41:14 -0700

On Tue, Apr 22, 2008 at 12:34 PM, Justin Giboney
<email@hidden> wrote:
> I am trying to put a automatic date and time field into my GUI.
>
>  I have a text field connected to a variable called "theDateTime" in my
> controller class. If I set the variable manually the text field works just
> fine. But I want it to update automatically. My code is attached.
>
>  Thank you
>
>  Justin Giboney
>
>  #import "Controller.h"
>
>
>  @implementation Controller
>
>  - (id) init {
>         [super init];
>         [NSThread detachNewThreadSelector:@selector(runClock) toTarget: self
> withObject: nil];
>         return self;
>  }
>
>  - (void) setDateTime {
>         NSAutoreleasePool *tempPool = [[NSAutoreleasePool alloc] init];
>         theDateTime = [NSDate date];
>         [tempPool release];
>  }

Sorry hit send by mistake on my prior email...

In the above you don't retain the object you assign to "theDateTime"
so it goes away when the current thread pool is drained. Also it isn't
clear how you expect the above simple setting of an ivar to trigger
your UI to update (you have it bound?). If so you shouldn't update UI
in this way from a secondary thread (especially if bindings are used).

You should use a proper setter (e.g. -setDateTime:(NSDate*)date) that
does the proper memory management and have your thread function create
the date object and call the setter. If you want to use a secondary
thread use performSelectorOnMainThread to get the update to take place
from the context of the main thread.

-Shawn
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: GUI Time Field
      • From: Justin Giboney <email@hidden>
References: 
 >GUI Time Field (From: Justin Giboney <email@hidden>)

  • Prev by Date: Re: GUI Time Field
  • Next by Date: Problems with [NSArray count]
  • Previous by thread: Re: GUI Time Field
  • Next by thread: Re: GUI Time Field
  • Index(es):
    • Date
    • Thread