开发者

How to pass method arguments to a selector

If I have a method like this:

- (void) foo
{
}

Then I can access it thr开发者_C百科ough a selector like this:

@selector(foo)

But what if I have a method like this:

- (void) bar:(NSString *)str arg2:(NSString *)str2
{

}

Then how do I access it through a selector?


To handle an arbitrary number of selectors you should use NSInvocation, but you can handle up to two objects using the standard performWithSelector stuff

[foo performSelector:@selector(bar:arg2:) withObject:obj1 withObject:obj2]


Remove the spaces, parameter types, and parameter names. In your example, this would become:

@selector(bar:arg2:)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜