NSInvocation

Personally, I think that a closer solution to your needs is the use of NSInvocation.

Something like the following will do the work:

indexPathanddataSourceare two instance variables defined in the same method.

------------------------------------------------------------------------

SEL aSelector = NSSelectorFromString(@"dropDownSelectedRow:withDataSource:");

if([dropDownDelegate respondsToSelector:aSelector]){

    NSInvocation *inv =[NSInvocation invocationWithMethodSignature:[dropDownDelegate methodSignatureForSelector:aSelector]];

    [inv setSelector:aSelector];

    [inv setTarget:dropDownDelegate];

    [inv setArgument:&(indexPath)atIndex:2];//arguments 0 and 1 are self and _cmd respectively,automatically set by NSInvocation

    [inv setArgument:&(dataSource)atIndex:3];//arguments 0 and 1 are self and _cmd respectively,automatically set by NSInvocation

    [inv invoke];

}

你可能感兴趣的:(NSInvocation)