0

私は、よく使用され、いくつかのボタンを返すカスタム ヘルパー メソッドを作成しています。各ボタンはもちろん、押されたときに独自のターゲット セレクターを持ちます。返されるボタンに指定されたセレクターが含まれるように、セレクターをパラメーターとしてこのメ​​ソッドに渡したいと思います。

しかし、セレクターをメソッドパラメーターとして渡す方法がわかりません。このようなもの:

-(returnedInstance)someMethod:(WhatClass?*)selectedFunction{

[SomeClassWithASelectorParameter method:whatever selector:@selector(selectedFunction)];

}

whereselectedFunctionはメソッドに渡されるパラメーターです。

WhatClass?*NSString と SELを作成しようとしましたが、結果は次のようになりました。

[NSInvocation invocationWithMethodSignature:]: メソッド署名の引数を nil にすることはできません

4

2 に答える 2

4

を渡してみませんSELか?つまり、セレクターです。そのようです:

-(returnedInstance)someMethod:(SEL)selectedFunction{
    [SomeClassWithASelectorParameter method:whatever selector:selectedFunction];
}

または、NSSelectorFromString次のようにします。

-(returnedInstance)someMethod:(NSString*)selectedFunction{
    [SomeClassWithASelectorParameter method:whatever selector:NSSelectorFromString(selectedFunction)];
}
于 2012-02-23T09:04:39.773 に答える
1

を使用したいのですがSEL、それを参照するときは、使用する必要はありませんselector

-(returnedInstance)someMethod:(SEL)selectedFunction{

    [SomeClassWithASelectorParameter method:whatever selector:selectedFunction];

}
于 2012-02-23T09:05:25.770 に答える