如何传递@selector说法? [英] How to pass argument in @selector?
本文介绍了如何传递@selector说法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何能够通过在 @选择
参数为我下面code?
[thisIconBtn addTarget:自我行动:@selector(changeIconState)forControlEvents:UIControlEventTouchUpInside]; - (无效)changeIconState:(*的UITableViewCell)的ThisCell
{
//做一点事
}
解决方案
首先,冒号是选择的一部分: @selector(changeIconState:)
二,行动是采取特定的一组参数的方法 - 你不能使用任何方法作为一个动作。通常情况下,操作是这样的:
- (无效)myAction:(id)的发送者;
,其中发送方是一个指针,它指向的发送操作的对象。在您的code,当thisIconButton被窃听,该按钮将作为发件人通过。
How can I pass an argument in the @selector
for my code below?
[thisIconBtn addTarget:self action:@selector(changeIconState) forControlEvents:UIControlEventTouchUpInside];
-(void)changeIconState:(UITableViewCell*)thisCell
{
//do something
}
解决方案
First, the colon is part of the selector: @selector(changeIconState:)
.
Second, actions are methods that take a particular set of parameters — you can't just use any method as an action. Usually, actions look like this:
- (void)myAction:(id)sender;
where sender is a pointer to the object that's sending the action. In your code, when thisIconButton is tapped, that button would be passed as the sender.
这篇关于如何传递@selector说法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文