2009-08-28 7 views
-1

GL 페인트 응용 프로그램을 개발 중입니다.배경에서 UIView 페인팅 NSThread?

개체를 페인트하려면 구현 된 UIView를 사용하고 있습니다.

시작 페인트 방법 :

- (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]; 
    } 
} 

그러나 (개체를 페인트하지 않습니다) 작동하지 않습니다.

무엇이 잘못 되었나요?

제발 도와주세요.

미리 감사드립니다.

+0

내가 아는 한, UI 객체는 스레드로부터 안전하지는 않지만, 내가 틀렸다는 것을 자유롭게 인정합니다. –

답변

1

모든 사용자 인터페이스 클래스는하지 스레드 안전하고 메인 스레드에서 호출해야합니다 있습니다 :이 경우

- (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]; } } 

, 당신은 가능성이 NSTimer를 사용하여 더 나을 것입니다.

+0

performSelectorOnMainThread가 아니어야합니까? – fbrereto

+0

D' oh! 네, 그렇게해야합니다 - 윈도우즈 박스에 맥 답을 제공하는 것입니다. 변경됨! – rpetrich