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:)
精彩评论