-1

私はGLペイントアプリケーションを開発しています。

任意のオブジェクトを描画するには、実装された 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];
    }
}

しかし、それは機能していません (オブジェクトをペイントしません)。

ここで何が問題なのですか?

みんな助けてください。

前もって感謝します。

4

1 に答える 1

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

于 2009-08-28T16:24:03.927 に答える