InitWithFireDateメソッドパラメータの説明.典型的なselectorとid userinfoの使用例


- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
date:初回fire時間
interval:fireを繰り返す間隔、repeatsがYESに適用
target:selfなどの送信オブジェクトを表す
aSelector:メソッドセレクタ、時間間隔でインスタンスメソッドの呼び出しを選択
userInfo:idタイプで、空にできます.aSelectorで強引に戻る前に伝わるタイプ.
repeats:YESの場合、タイマは失効または解放されるまで繰り返し、NOの場合、タイマは1回繰り返し送信すると失効します.
/**
 *     NSTimer
 */
-(void)timerTest
{
	NSNumber* testValue = [NSNumber numberWithInt:100];
	NSDate* fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:5]; //5s       fire
	NSTimer* testTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:5 target:self selector:@selector(timerSelector:) userInfo:testValue repeats:YES];
	[[NSRunLoop currentRunLoop] addTimer:testTimer forMode:NSDefaultRunLoopMode];
}

/**
 * NSTimer     
 */
-(void)timerSelector:(id)sender
{
	int value = [(NSNumber*)[sender userInfo] intValue];	//         
	NSLog(@"timerTest value: %d", value);
	// ...
}

----参考内容:
すみません、NSTimerはどう使いますか?
@selectorのメソッド名にパラメータを付けることはできません
NSTimerクラスの使用
  http://linglong117.blog.163.com/blog/static/27714547201158545587/
-----
initWithFireDate:interval:target:selector:userInfo:repeats:
Initializes a new NSTimer object using the specified object and selector.
- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
Parameters
date
The time at which the timer should first fire.
seconds
For a repeating timer, this parameter contains the number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.
target
The object to which to send the message specified by aSelector when the timer fires. The target object is retained by the timer and released when the timer is invalidated.
aSelector
The message to send to target when the timer fires. The selector must have the following signature:
- (void)timerFireMethod:(NSTimer*)theTimer
The timer passes itself as the argument to this method.
userInfo
Custom user info for the timer. The object you specify is retained by the timer and released when the timer is invalidated. This parameter may be nil.
repeats
If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
Return Value
The receiver, initialized such that, when added to a run loop, it will fire at date and then, if repeats is YES, every seconds after that.
Discussion
You must add the new timer to a run loop, using addTimer:forMode:. Upon firing, the timer sends the message aSelector to target. (If the timer is configured to repeat, there is no need to subsequently re-add the timer to the run loop.)
Availability
Available in iOS 2.0 and later.
Related Sample Code
TableViewSuite
Declared In
NSTimer.h