• 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 を使用してやりたい処理をメインスレッドにスケジュールしてやる。

   1  @interface	Operation : NSOperation {
   2  }
   3  @end
   4  @implementation	Operation
   5  -	(void)
   6  Sub {
   7  NSLog( @"Sub:%@", [ NSThread currentThread ] );
   8      //  UIKit を使う処理
   9  }
  10  
  11  -	(void)
  12  main {
  13  NSLog( @"main:%@", [ NSThread currentThread ] );
  14  	[ self performSelectorOnMainThread:@selector(Sub) withObject:nil waitUntilDone:NO ];
  15  }
  16  @end
  17  
  18  
  19  {
  20  	NSOperationQueue*	w = [ [ [ NSOperationQueue alloc ] init ] autorelease ];
  21  	[ w addOperation:[ [ Operation alloc ] init ] ];
  22  }

posted by Face Saturn on Tue 16 Nov 2010 at 02:29

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1854
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ