本文介绍了在iOS中使用performSelector有什么用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 performSelector 有点困惑。我已经在谷歌上搜索了。但我不清楚。任何人都可以解释 performSelector 的作用。

I am little bit confused regarding performSelector. I already googling . but not clear to me. anyone can explain the role of performSelector.

谢谢

[self btnClicked];

[self performSelector:@selector(btnClicked)]; 


-(void)btnClicked
{

    NSLog(@"Method Called";
}

对我来说都很好。这两者之间有什么区别。 [self btnClicked] [self performSelector:@selector(btnClicked)] ;

both are woking fine for me. what is difference between these two. [self btnClicked] and [self performSelector:@selector(btnClicked)];

推荐答案

两者在使用时非常相同,但后者的优势在于您可以动态确定在运行时调用哪个选择器。

The two are pretty identical when used as you have demonstrated, but the latter has the advantage that you can dynamically determine which selector to call at runtime.

SEL selector = [self gimmeASelectorToCall];
[self performSelector: selector];

这篇关于在iOS中使用performSelector有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 01:25