iOS - 如何使用多个参数和 afterDelay 实现一个 performSelector? [英] iOS - How to implement a performSelector with multiple arguments and with afterDelay?

查看:29
本文介绍了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:

indexPathdataSource 是在同一个方法中定义的两个实例变量.

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆