16th Tue
NSOperation が動くスレッド
NSOperationQue は(当然のことながら)別スレッドで動くので
中の NSOperation からUIKit を扱うときは
performSelectorOnMainThread
を使用してやりたい処理をメインスレッドにスケジュールしてやる。
ruby>>
@interface Operation : NSOperation {
}
@end
@implementation Operation
- (void)
Sub {
NSLog( @"Sub:%@", [ NSThread currentThread ] );
// UIKit を使う処理
}
- (void)
main {
NSLog( @"main:%@", [ NSThread currentThread ] );
[ self performSelectorOnMainThread:@selector(Sub) withObject:nil waitUntilDone:NO ];
}
@end
{
NSOperationQueue* w = [ [ [ NSOperationQueue alloc ] init ] autorelease ];
[ w addOperation:[ [ Operation alloc ] init ] ];
}
<<--
posted by
Saturn on Tue 16 Nov 2010 at 02:32 with 0 comments