开发者

How to pass method arguments to a selector

开发者 https://www.devze.com 2023-01-19 04:52 出处:网络
If I have a method like this: - (void) foo { } Then I can access it thr开发者_C百科ough a selector like this:

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

精彩评论

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