NSTimerとuserInfoの使い方。
よく使うのにたまに忘れがちなのでNSTimerの使い方かきました。userInfoの使い方とか参考になれば。
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/doc/uid/TP40003747
-(void) intervalTimer:(NSTimer *)inTimer{ NSMutableDictionary * dic = [inTimer userInfo]; UIImageView * imageView = [dic objectForKey:@"imageView1"]; // imageViewをuserInfoから引っ張る if( timerCounter >= 1.0f ){ // int timerCounter; [timer invalidate]; timerCounter = 0.0f; } NSLog(@"looping."); } -(void) main{ UIImageView * imageView = [UIImageView alloc]init]; // NSMutableDictionaryに入れてTimer scheduleTimerWithIntervalのuserInfoから参照する UIImageViewをテスト的につくってみる。 float timerInterval = 0.1f; NSMutableDictionary * dic = [NSmutableDictionary alloc]init] [dic addValue:imageView forKey:@"imageView"]; timer = [NSTimer scheduledTimerWithTimeInterval:timerInterval target:self selector:@selector(intervalTimer:) userInfo:dic repeats:YES]; // NSTimer * timer; }