On Tue, Apr 22, 2008 at 12:34 PM, Justin Giboney <[EMAIL PROTECTED]> 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 (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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]