setArgument:atIndex:
番号で指定した引数に値をコピーします
-(void)setArgument:(void *)buffer: atIndex:(int)index:
解説
番号で指定した引数に値をコピーします。これでメソッドに引数の値を渡すことが出来ます。
指定する番号のうち0はself、1は_cmdになっています(デバッガを見てください)ので、2以降が通常見える引数となります。
引数を一つ持つメソッドに値を渡したいときは、番号2でセットします。
指定する番号がメソッドの引数の数より多いときはNSInvalidArgumentExceptionを起こします。
返り値
( void )
なし
引数
( void * )buffer
バッファのポインタ
( int )index
セットする引数のインデックス値(隠し引数が2つあるので、通常は2から始まる)
フレームワーク
Foundation
クラス
NSInvocation
Instance Methods
使用可能
10.0
iOS2.0
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { NSMethodSignature *aSignature ; //起動オブジェクト NSInvocation *invocation ; //セレクタ SEL aSelector = @selector( timerControl: ); NSString *aBuffer=@"aaa"; //メソッドシグネチャをセット aSignature = [ self methodSignatureForSelector:aSelector ]; //起動オブジェクトを作成 invocation = [ NSInvocation invocationWithMethodSignature:aSignature ]; //ターゲットはself [ invocation setTarget: self ]; //セレクタをセット [ invocation setSelector: aSelector ]; //セレクタをセット [ invocation setArgument:&aBuffer atIndex:2]; //起動する [ invocation invoke ]; } -(void) timerControl:(NSString *)arg { NSLog(@"%@",arg); } @end