views:

599

answers:

2

hi guys.

I am developing GL paint application.

To paint any object, I am using UIView that implemented.

Starting paint method :

- (void)viewDidLoad {
    ....
    [NSThread detachNewThreadSelector:@selector(paintingObjects) 
                             toTarget:self
                           withObject:nil];
}

- (void)paintingObjects {
    while(1) {
        [NSThread sleepForTimeInterval:2];
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        ImplementedView *tmp = [self view];
        [tmp draw];
        [pool drain];
    }
}

But it is not working (doesn't paint object).

What is wrong here ?

Please help me guys.

Thanks in advance.

+1  A: 

All user-interface classes are not thread-safe and must be called from the main thread:

- (void)paintingObjects {
    while(1) {
        [NSThread sleepForTimeInterval:2];
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        ImplementedView *tmp = [self view];
        [tmp performSelectorOnMainThread:@selector(draw) withObject:nil waitUntilDone:YES];
        [pool drain];
    }
}

In this case, you would likely be better off using NSTimer.

rpetrich
Shouldn't that be performSelectorOnMainThread?
fbrereto
D'oh! Yes, it should be--thats what I get for providing Mac answers on my Windows box. Changed!
rpetrich
A: 

Cool. It works fine.

Thanks a lot.