• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

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 Saturn on Tue 16 Nov 2010 at 02:32 with 0 comments