Hey there.. I've only been at this for a week, plugging a way so far, but hit a glitch where I thought I should ask for some help.
I'm trying to animate an object on a UIView. I've decided to do this by subclassing NSThread, and having that pass a message back to my View Contoller after a delayed interval.
This appears to work OK, the thread is launched, the messages are passed back and forth, except that the UIView doesn't appear to update until the Thread's main method is complete. I can see the methods being called proplerly (NSLog's work as I think they should)... I'd rather have the threads run concurrently so that one can update the other.
Any ideas what I might be doing wrong?
Code Snippets:
The problem is that I see "ThreadMessage finished" in the console, but the animations produced by "target.center = touchPoint" and "yLabel.text..." don't show up until after the 10 second delay produced by TestThread.m's " [NSThread sleepForTimeInterval:10.0];"
Any help would be appreciated!
I'm trying to animate an object on a UIView. I've decided to do this by subclassing NSThread, and having that pass a message back to my View Contoller after a delayed interval.
This appears to work OK, the thread is launched, the messages are passed back and forth, except that the UIView doesn't appear to update until the Thread's main method is complete. I can see the methods being called proplerly (NSLog's work as I think they should)... I'd rather have the threads run concurrently so that one can update the other.
Any ideas what I might be doing wrong?
Code Snippets:
Code:
TestThread.m:
- (void) main {
NSAutoreleasePool *autorelease = [[NSAutoreleasePool alloc] init];
NSLog(@"Thread Started");
[NSThread sleepForTimeInterval:2.0];
NSLog(@"Thread Still here...");
[viewController threadMessage];
[NSThread sleepForTimeInterval:10.0];
NSLog(@"Thread Still here2...");
[autorelease release];
}
- (void) setParent:(id)sender {
viewController = sender;
NSLog(@"View Contoller set");
}
@end
AppDelegate.m:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
TestThread *myThread = [[TestThread alloc] init];
[myThread setParent:viewController];
[myThread start];
}
ViewController.m:
- (void)threadMessage {
NSLog(@"ThreadMessage");
CGPoint touchPoint;
touchPoint.x = 20;
touchPoint.y = 20;
target.center = touchPoint;
yLabel.text = @"New Message";
NSLog(@"ThreadMessage finished");
}
The problem is that I see "ThreadMessage finished" in the console, but the animations produced by "target.center = touchPoint" and "yLabel.text..." don't show up until after the 10 second delay produced by TestThread.m's " [NSThread sleepForTimeInterval:10.0];"
Any help would be appreciated!