多个参数和afterDelay实现performSelector

多个参数和afterDelay实现performSelector

本文介绍了iOS - 如何使用多个参数和afterDelay实现performSelector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS新手。我有一个选择器方法如下 -

I am an iOS newbie. I have a selector method as follows -

- (void) fooFirstInput:(NSString*) first secondInput:(NSString*) second
{

}

我正在努力实现像这个 -

I am trying to implement something like this -

[self performSelector:@selector(fooFirstInput:secondInput:) withObject:@"first" withObject:@"second" afterDelay:15.0];

但这给我一个错误说 -

But that gives me an error saying -

Instance method -performSelector:withObject:withObject:afterDelay: not found

关于我缺少什么的任何想法?

Any ideas as to what I am missing?

推荐答案

就我个人而言,我认为更贴近您的需求的是使用NSInvocation。

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

以下内容将完成以下工作:

Something like the following will do the work:

indexPath dataSource 是在同一方法中定义的两个实例变量。

indexPath and dataSource are 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];
}

这篇关于iOS - 如何使用多个参数和afterDelay实现performSelector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:58