Skip navigation.
 
mlRe: GUI Time Field
FROM : Shawn Erickson
DATE : Tue Apr 22 22:41:14 2008

On Tue, Apr 22, 2008 at 12:34 PM, Justin Giboney
<<email_removed>> 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

Related mailsAuthorDate
mlGUI Time Field Justin Giboney Apr 22, 21:34
mlRe: GUI Time Field Shawn Erickson Apr 22, 22:34
mlRe: GUI Time Field Shawn Erickson Apr 22, 22:41
mlRe: GUI Time Field Justin Giboney Apr 23, 00:24
mlRe: GUI Time Field Shawn Erickson Apr 23, 00:47