macOS/iOS API解説

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

目次

setSelector:

INDEX>Foundation>NSInvocation

起動オブジェクトにセレクタをセットします
-(void)setSelector:(SEL)selector:

解説

起動オブジェクトにセレクタをセットします。

返り値

( void )

なし

引数

( SEL )selector

セットするセレクタ、@selector()コンパイラディレクティブが使えます

クラス

NSInvocation

Instance Methods

使用可能

10.0
iOS2.0

参照

- selector

例文

#import "MyObject.h"
@implementation MyObject

NSTimer *timer=nil;

- (IBAction)myAction:(id)sender
{
    	//メソッドシグネチャ
	NSMethodSignature *aSignature ;
    
	//起動オブジェクト
	NSInvocation *invocation ;
	
	//セレクタ
    SEL aSelector ;
	
	//セレクタをセット
    aSelector  = @selector( timerControl );
	
	//メソッドシグネチャをセット
    aSignature = [ self methodSignatureForSelector:aSelector ];
	
	//起動オブジェクトセット
    invocation = [ NSInvocation invocationWithMethodSignature:aSignature ];
	
	//ターゲットをセット
    [ invocation setTarget: self ];
	
	//セレクタをセット
    [ invocation setSelector: aSelector ];
	
	//ターイマーで呼び出す
	timer = [NSTimer scheduledTimerWithTimeInterval:1
							invocation:invocation
								repeats:YES];

}

-(void) timerControl{
NSLog(@"...");
}

@end