macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

setFireDate:

タイマーが起動する日付・時間をセットします
-(void)setFireDate:(NSDate *)date:

解説

タイマーが起動する日付時間をセットします。

返り値

( void )

なし

引数

( NSDate * )date

タイマーが起動する日付・時間

クラス

NSTimer

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"
@implementation MyObject

NSTimer *timer=nil;

- (IBAction)myAction:(id)sender
{
	NSDate *theDate = [NSDate dateWithTimeIntervalSinceNow:5]; //10秒後

//userInfoに使う辞書を作成
	NSDictionary *userInfoDictionary =[NSDictionary dictionaryWithObjectsAndKeys:
						@"value1",@"key1",
						@"value2",@"key2",
						@"value3",@"key3",nil];
	//タイマー作成
	timer = [NSTimer scheduledTimerWithTimeInterval:1.0
							target:		self
							selector:	@selector(timerControl:)
							userInfo:	userInfoDictionary
								repeats:NO];
	//起動時間セット
	[timer setFireDate:theDate];
}
- (IBAction)fire:(id)sender
{
}
- (IBAction)stop:(id)sender
{
	//動いていたら無効に
	if ([timer isValid]){
		[timer invalidate];
	}
}
-(void) timerControl:(NSTimer *)aTimer
{
	NSLog(@"...%@",[[aTimer userInfo] objectForKey:@"key2"]);
	NSLog([[timer fireDate] description]);
}
@end