macOS/iOS API解説

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

目次

selector

INDEX>Foundation>NSInvocation

起動オブジェクトにセットされているセレクタを返します

解説

起動オブジェクトにセットされているセレクタを返します。

返り値

( SEL )

セレクタ

引数

クラス

NSInvocation

Instance Methods

使用可能

10.0
iOS2.0

例文

#import "MyObject.h"
@implementation MyObject

NSTimer *timer=nil;

- (IBAction)myAction:(id)sender
{
	NSMethodSignature *aSignature ;
    
	//起動オブジェクト
	NSInvocation *invocation ;
	
	//セレクタをセット
    SEL aSelector  = @selector( timerControl );
	
	//セレクタのメソッドシグネチャをセット
    aSignature = [ self methodSignatureForSelector:aSelector ];
	
	//起動オブジェクトを作る
	invocation = [ NSInvocation invocationWithMethodSignature:aSignature ];
	
	//ターゲットはself
    [ invocation setTarget: self ];
	
	//セレクタをセット
    [ invocation setSelector: aSelector ];
    //[ invocation invoke ];//起動する
    NSLog(NSStringFromSelector([invocation selector]));

                        
timer = [NSTimer scheduledTimerWithTimeInterval:1
                        invocation:invocation
                            repeats:YES];

}

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

@end