美文网首页
NSInvocation

NSInvocation

作者: FancyMF | 来源:发表于2018-12-17 10:24 被阅读0次

    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

          本文链接:https://www.haomeiwen.com/subject/sglqkqtx.html